If you think a bug might affect users in the 57 release, please set the correct tracking and status flags for Release Management.

Javascript - Incorrect value on arithmetic operation

VERIFIED DUPLICATE of bug 5856

Status

()

Firefox
General
VERIFIED DUPLICATE of bug 5856
9 years ago
9 years ago

People

(Reporter: whitewebcoder, Unassigned)

Tracking

Firefox Tracking Flags

(Not tracked)

Details

(Reporter)

Description

9 years ago
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

Updated

9 years ago
Status: UNCONFIRMED → RESOLVED
Last Resolved: 9 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: 5856
Status: RESOLVED → VERIFIED
You need to log in before you can comment on or make changes to this bug.