Skip to main content
Participating Frequently
September 1, 2006
Question

why 3.78-3=0.78 but 3000.78-3000 !=0.78?????

  • September 1, 2006
  • 3 replies
  • 382 views
just found an intreesting thing,

trace (3000.78-3000) // 0.7800000000002
trace (3.78-3) // 0.78

Why???????
This topic has been closed for replies.

3 replies

chiangwenAuthor
Participating Frequently
September 3, 2006
I got it! Thanks, David and Kglad. :-)
kglad
Community Expert
Community Expert
September 3, 2006
you're welcome.
Inspiring
September 2, 2006
"kglad" <webforumsuser@macromedia.com> wrote in message
news:edaikj$b3g$1@forums.macromedia.com...
> binary computers do not use decimal representation of
> numbers. so, you will see rounding errors if you look closely
> enough.

To add to what kglad said, this holds true across the board on binary
computers. In other words, this is not a bug in Flash: it's a fact of life
in dealing with the sorts of computers we all use. You'll see the same
rounding errors in JavaScript, Java, C#, Perl, PHP, etc., etc., etc., -- to
a greater or lesser extent, depending on the degree of accuracy to which
numbers are stored in that language.


David Stiller
Adobe Community Expert
Dev blog, http://www.quip.net/blog/
"Luck is the residue of good design."


kglad
Community Expert
Community Expert
September 2, 2006
binary computers do not use decimal representation of numbers. so, you will see rounding errors if you look closely enough.