This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes HTML, CSS and JavaScript and the fly likes 1.1*100=?    1.11*100=? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "1.1*100=?    1.11*100=?" Watch "1.1*100=?    1.11*100=?" New topic
Author

1.1*100=? 1.11*100=?

Liu Zhixiang
Ranch Hand

Joined: Aug 12, 2006
Posts: 32
Hello everyone!
Just like subject!Why the result is not 110 and 111,but 110.00000000000001 etc?
Why the capability of Javascript's Math is poor?


I Think Therefore I Am
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 41017
    
  43
It's not JavaScript that's poor at math, it's computers in general. The reason is that math is performed base 2, not base 10, and few floating point numbers have an exact representation in base 2. All the details (which apply to all languages, not just Java or JavaScript) can be found in two articles linked in #20 in the Java Beginners FAQ.


Ping & DNS - my free Android networking tools app
Alec Lee
Ranch Hand

Joined: Jan 28, 2004
Posts: 569
How do we achieve exact floating point calculation in Javascript? Are there any BigDecimal equivalent classes ?
 
Don't get me started about those stupid light bulbs.
 
subject: 1.1*100=? 1.11*100=?
 
Similar Threads
97 Things Every Programmer Should Know - A Question
jsp bean problem
advertising phrases I hate
Switch statement
Sun Certification Voucher for $150