I know JavaScript has a notorious problem with math that can cause math problems to return wrong with wonky decimal numbers. But how does one do a simple addition and subtraction in JS and not have a wonky result? And the numbers for the addition and subtraction are not fixed numbers and relay on variables. For example...
addition
var a = 3.94
var b = 0.5
var r = a + b
console.log(r) //4.4399999999999995
subtract
var a = 4.22
var b = 0.5
var r = a - b
console.log(r) //3.7199999999999998
I am aware of the math floating point issue in JS but I am looking for a simple solution to not have this issue occur when doing some addition and subtraction.
No comments:
Post a Comment