• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

1.1*100=? 1.11*100=?

 
Liu Zhixiang
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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?
 
Ulf Dittmer
Rancher
Posts: 42968
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How do we achieve exact floating point calculation in Javascript? Are there any BigDecimal equivalent classes ?
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic