division of float numbers

11 Ansichten (letzte 30 Tage)
Fatina Shukur
Fatina Shukur am 29 Okt. 2017
Kommentiert: Walter Roberson am 30 Okt. 2017
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

Antworten (1)

Star Strider
Star Strider am 29 Okt. 2017
See the documentation for the format (link) function.
Specifically:
format bank
will do what you want.
  9 Kommentare
Star Strider
Star Strider am 29 Okt. 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
Walter Roberson am 30 Okt. 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 ?

Melden Sie sich an, um zu kommentieren.

Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by