Closed Bug 1431780 Opened 7 years ago Closed 7 years ago

Bug in Math Calculation

Categories

(Developer Documentation Graveyard :: JavaScript, enhancement)

All
Other
enhancement
Not set
normal

Tracking

(Not tracked)

RESOLVED INVALID

People

(Reporter: kyle.valdillez, Unassigned)

Details

(Whiteboard: [specification][type:bug])

What did you do? ================ 1. Opened console 2. Entered 16.4*100 and hit enter 3. Get 1639.9999999999998 when it should be 1640 What happened? ============== The result returned is wrong. What should have happened? ========================== It should have returned 1640. Is there anything else we should know? ======================================
This issue has occurred running in Chrome and Node Shell.
This is a correct implementation of floating point math (64-bit, IEEE 754 to be precise). Here's some more information: https://developer.mozilla.org/en-US/docs/Web/JavaScript/A_re-introduction_to_JavaScript#Numbers https://stackoverflow.com/questions/588004/is-floating-point-math-broken#588014 https://en.wikipedia.org/wiki/IEEE_754 https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html If you need to do decimal math in JS, you either work with integers (for example, storing US currency as pennies or tenths of pennies), or use a arbitrary-precision library like decimal.js: https://github.com/MikeMcl/decimal.js/
Status: UNCONFIRMED → RESOLVED
Closed: 7 years ago
Component: General → JavaScript
Product: Mozilla Developer Network → Developer Documentation
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.