Came across a weird result in Javascript (actually python as well)
var a = 80.1
var b = 100
var a/b = 0.8009999999999999
var a = 80.1
var b = 100
var a*b = 8009.999999999999
Same does not happen for 80.2
Would like to know why this happens
Came across a weird result in Javascript (actually python as well)
var a = 80.1
var b = 100
var a/b = 0.8009999999999999
var a = 80.1
var b = 100
var a*b = 8009.999999999999
Same does not happen for 80.2
Would like to know why this happens
The mathematical representation used by JavaScript
is in IEEE 754
so there are not all numbers that can be represented with IEEE 754
. If you want to perform the division and get the proper result then you need to use the rounding of the decimal values like,
var a = 80.1;
var b = 100;
console.log((a/b).toFixed(3));