question concerning rounding of numbers
2 Ansichten (letzte 30 Tage)
Ältere Kommentare anzeigen
Jakob Sievers
am 26 Mär. 2015
Beantwortet: Jakob Sievers
am 27 Mär. 2015
Hi
I am having trouble rounding a number to a fixed number of digits. Can anyone explain the problem I am encountering? (As shown in this figure)
0 Kommentare
Akzeptierte Antwort
James Tursa
am 26 Mär. 2015
1 Kommentar
John D'Errico
am 26 Mär. 2015
As has been said, no matter how hard you try, you cannot represent 30.7 exactly as a double precision number. That is a binary representation, and your number is not exactly representable.
In fact, this is true of almost all the numbers you will write in decimal form. The exceptions are integers of a reasonable size, and those numbers that can be written as sums of limited negative powers of 2. So 0.5, and 0.375 will be exactly represented.
Weitere Antworten (2)
Siehe auch
Kategorien
Mehr zu Logical finden Sie in Help Center und File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!