Closed Bug 1462897 Opened 6 years ago Closed 6 years ago

The "better solution" is simply a more bad one

Categories

(Developer Documentation Graveyard :: JavaScript, defect, P2)

All
Other
defect

Tracking

(Not tracked)

RESOLVED FIXED

People

(Reporter: wiimm, Unassigned)

References

()

Details

:: Developer Documentation Request Request Type: Correction Gecko Version: unspecified Technical Contact: :: Details The number 1.005 cant be stored exact and is internally stored as 1.0049999999xxxx. So the mathematical rounding to 1.00 is absolutely correct. The "better solution" simply ignores these fact and produces other errors. So the result of round(1.0049999999999999,2) is 1.01 too -- definitely a bug! This is a general problem of understanding, how floating point number are stored (based on power of 2; but humans write numbers based on power of 10). And so I think, than an explanation, why 1.005 id rounded to 1.00 and not to 1.01 is much better than providing an bad solution that have other mathematical issues and is simply buggy.
Component: General → JavaScript
Priority: -- → P2
I think the page is explaining completely different thing than API itself. it's better just changing the demo code not to implement precisionRound but directly use the Math.round API itself, and remove the "better solution" section.
Agree, removing the "better solution" section is the best option.
The demo is also updated.
Status: UNCONFIRMED → RESOLVED
Closed: 6 years ago
Resolution: --- → FIXED
You need to log in before you can comment on or make changes to this bug.