MozillaZine


0.07*0.03 = 0.0021000000000000003

User Help for Mozilla Firefox
jslomp
New Member
 
Posts: 1
Joined: September 5th, 2021, 9:08 am

Post Posted September 5th, 2021, 9:13 am

Hello Firefox dev team.

This bug is very old and i have noticed this with javascript development but i was young and believed that i did something wrong. Now in my invoice calculator i did amount * price. 0.07 * 0.03 and it returned 0.0021000000000000003

i have seen this behavior before and always rounded it, but since i am older i realize this is just a very old bug that no-one ever tended to fix.
if you go and use your calculator, the correct answer is of course: 0.0021.

The weird part is, Chrome/Edge and Internet explorer all return the same (wrong) answer.

dickvl

User avatar
 
Posts: 53551
Joined: July 18th, 2005, 3:25 am

Post Posted September 5th, 2021, 12:52 pm

This is caused by the difference of how fixed point numbers and floating point numbers are stored and 7 is a problem: 0.0007*1e2 -> 0.06999999999999999, so you may need to round numbers.

If you want to work accurately with fragmented numbers then use integers and shift the decimal point by multiplying with 100 or 1000.

Return to Firefox Support


Who is online

Users browsing this forum: Google Adsense [Bot] and 7 guests