how to get only 3 digit under point
Mostra commenti meno recenti
Hello,
I want to get the only 3 digit under the point. For example,
a = 123.4567;
and I want to get just modify_a = 123.456. I tried the code
a = round(a*10^3)/10^3
but the result is , a = 123.457 0;
How can I remove the '0' point? please help me.
Thank you in advance.
2 Commenti
octopus_love
il 11 Set 2017
Walter Roberson
il 11 Set 2017
msgbox( sprintf('%.3f', var_a) )
provided that rounding is acceptable.
Note: round(a,3) does rounding, not truncation. 123.4567 would round to 123.457
Risposta accettata
Più risposte (1)
Walter Roberson
il 11 Set 2017
0 voti
In order to do that you will need to override the important internal routine toolbox/matlab/lang/@double/display to implement an additional "format" that has exactly three decimal places and which truncates. I would expect that would be a notable amount of work to get right without interfering with any of the current uses of the routine.
The built in "format" can display 2 digits after the decimal place ("format bank" or sometimes "format short g") or 4 digits after the decimal place ("format short" or "format short eng"), or 15 digits after the decimal place ("format long"), or up to 15 digits after the decimal place, stopping the remaining digits of the 15 are all 0. The "format" routines all round.
For any other format like 3 digits exactly with truncation, you need to override the display method. Or you could do the display formatting yourself, using sprintf() or fprintf()
Categorie
Scopri di più su 숫자형 in Centro assistenza e File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!