need solution: 30.01 + 30.03= 60.0400000000000006


EJB design: need solution: 30.01 + 30.03= 60.0400000000000006

  1. hi all, pls advice any solution to the following overflow problem while adding 2 numbers in javascript. 30.01 + 30.03 = 60.0400000000000006 whereas 30.01 + 30.04= 60.05 thanks
  2. In Java you would solve this by using a double instead of a float. In JavaScript you cannot make that choice so it is probably easiest to use cent values in your scripts and divide by 100 to present values. S.
  3. If you are dealing with kind of accounting stuff, you should use BigDecimal class. Mithat
  4. Any particular reason why a javascript error is posted in the ejb design forum?
  5. You can always use something like this: function formatNumber(number) { return Math.round (number *100) /100; }
  6. Its mainly because of inability to represent 0.1 exactly in binary. The problem is not with java,same result will be observed in c,c++,basic,pascal,etc..... Regards, Sanket