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)
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.
Updated•6 years ago
|
Component: General → JavaScript
Priority: -- → P2
Comment 1•6 years ago
|
||
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.
Comment 3•6 years ago
|
||
Removed unrelated sections.
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round$compare?locale=en-US&to=1385078&from=1383484
also created PR to change the demo
https://github.com/mdn/interactive-examples/pull/956
Comment 4•6 years ago
|
||
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.
Description
•