1

I have a problem with javascript number. My problem is that I have a currency field in HTML and when I use javascript to calculate with another field; then if this input field has the number of digits > 15 then this is auto rounded. You can try this in firebug. E.g:

(9999999999999999);
10000000000000000 

How do I fix this?

hello_world
  • 29
  • 10
tandaica0612
  • 369
  • 10
  • 23

1 Answers1

2

You have a currency field that you care is rounding past 9999999999999999??

I'm impressed right there :P

It's a limitation of having large floating point numbers. There's no easy way to fix it short of getting a bigint javascript library, I'm sure there's a few out there. But honestly, why do you care?

  • 2
    Javascript numbers aren't 32-bit. They're IEEE-754 doubles, which take 64 bits: 1 sign, 11 exponent, 52 (explicit) mantissa. – Ken Apr 08 '11 at 06:05
  • @Ken, yes you're right, I'm tired. It's a limitation of floating point numbers. Better? :) –  Apr 08 '11 at 06:08