Tuesday, May 25, 2010

JavaScript Addition

Apparently, IEEE makes standards for JavaScript that make accurate addition difficult.

I haven't found the exact standard, but I'm looking for it.

When you add numbers with decimals, JavaScript will add value.

For instance:

115.04 + 15 = 130.04000000000002

Instead of 130.04

So, I found a work around for this. Use *.toPrecision(##).

toPrecision will allows you to truncate the value.

1 comment:

  1. I am using it for something else altogether. I need to truncate a value and then add .5 to it.

    This help! Thanks

    ReplyDelete