question concerning rounding of numbers

2 vues (au cours des 30 derniers jours)
Jakob Sievers
Jakob Sievers le 26 Mar 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)

Réponse acceptée

James Tursa
James Tursa le 26 Mar 2015
  1 commentaire
John D'Errico
John D'Errico le 26 Mar 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.

Connectez-vous pour commenter.

Plus de réponses (2)

Luuk van Oosten
Luuk van Oosten le 26 Mar 2015
Yes, I believe your problem is described here

Jakob Sievers
Jakob Sievers le 27 Mar 2015
Thanks for all of your comments. They helped me greatly!

Catégories

En savoir plus sur Logical dans Help Center et File Exchange

Tags

Community Treasure Hunt

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

Start Hunting!

Translated by