division of float numbers
11 views (last 30 days)
Show older comments
Hi, MATLAB is usually showed the result of float number with four digits, how we can get only two digits after the decimal point. Ex: a = 532.7589 I want to get it as a=532.76 and please I DONOT want to use fprintf('%.2f', a) Thanks in advance
0 Comments
Answers (1)
Star Strider
on 29 Oct 2017
9 Comments
Star Strider
on 29 Oct 2017
If you want what you describe, you have to use the round function in addition to format short g:
format shortg
x = [4.548934 89.0009];
x = round(x,2)
x =
4.55 89
You have to live with the constraints of the software you use.
Walter Roberson
on 30 Oct 2017
Now, 34.00000000000000710542735760100185871124267578125 is not an integer, but it rounds to an integer -- it is the very next representable number after 34 exactly. Should 34.00000000000000710542735760100185871124267578125 be displayed as 34 or as 34.00 ?
See Also
Categories
Find more on Logical in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!