Closed Bug 452198 Opened 13 years ago Closed 13 years ago

javascript mathematics : 0.4 + 0.2 = 0.6000000000000001

Categories

(Firefox :: General, defect)

x86
Windows XP
defect
Not set
normal

Tracking

()

RESOLVED DUPLICATE of bug 5856

People

(Reporter: nico_debeissat, Unassigned)

Details

User-Agent:       Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1
Build Identifier: Mozilla/5.0 (Windows; U; Windows NT 5.1; fr; rv:1.9.0.1) Gecko/2008070208 Firefox/3.0.1

Using javascript, the addition 0.4 + 0.2 gives 0.6000000000000001, whereas 0.6 + 0.2 = 0.8. Why is that extra decimal added ? That adds complexity in my code.

Reproducible: Always

Steps to Reproduce:
1. var x = 0.4 + 0.2. Value of x is 0.6000000000000001.
Actual Results:  
0.6000000000000001

Expected Results:  
0.6
Version: unspecified → Trunk
Because floating point numbers can never be represented exactly in computers. Please try reading any popular book on programming that covers floating point arithmetic
Status: UNCONFIRMED → RESOLVED
Closed: 13 years ago
Resolution: --- → DUPLICATE
Duplicate of bug: js-ieee-double-hurts
You need to log in before you can comment on or make changes to this bug.