Closed Bug 460943 Opened 17 years ago Closed 17 years ago

Javascript - Incorrect value on arithmetic operation

Categories

(Firefox :: General, defect)

x86
All
defect
Not set
normal

Tracking

()

VERIFIED DUPLICATE of bug 5856

People

(Reporter: whitewebcoder, Unassigned)

Details

User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.12) Gecko/20080129 Iceweasel/2.0.0.12 (Debian-2.0.0.12-0etch1) Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.2; en; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1 I try this code on Linux and Windows on different hardware, and the same bug occurs. Here is the javascript code : PxSimul = 100; Rem1=47; Rem2=16; Rem3=0; Base100 = (1 - (Rem1 / 100)) * (1 - (Rem2 / 100)) * (1 - (Rem3 / 100)); document.write(Base100); document.write("<br/>"); document.write(Base100 * 100); document.write("<br/>"); document.write(Math.round(Base100 * 10000) / 100); document.write("<br/>"); On the first number, I have 0,4452. But when I multiply it by 100, I've got 44.519999999999996. The only way I've found to soluce this bug is to make a round of the variable. Reproducible: Always Steps to Reproduce: Add this Javascript code in a HTML Page. Reproduced on Windows : Firefox, IE, Chrome Linux : Firefox Actual Results: Base100 * 100 = 44.519999999999996 Expected Results: Base100 * 100 = 44.52
Status: UNCONFIRMED → RESOLVED
Closed: 17 years ago
Resolution: --- → DUPLICATE
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.