I know it's probably due to some sort of rounding technique, but clearly 6.53 + 8 should only equal 14.53. My questions are, why is this happening, and how can I get an accurate sum?
var x = 6.53 + 8;
console.log(x);// 14.530000000000001
I know it's probably due to some sort of rounding technique, but clearly 6.53 + 8 should only equal 14.53. My questions are, why is this happening, and how can I get an accurate sum?
var x = 6.53 + 8;
console.log(x);// 14.530000000000001
It is normal behavior with JS
, Try to use toFixed(2)
like this
var x = 6.53 + 8;
console.log(x.toFixed(2));
Decimal point numbers are represented differently in a computer...and have this problem..u can have that happen in many programming languages...round your number to a certain precision...as long as you don't do advanced computation with JavaScript you will be fine. More info. https://www.w3schools.com/js/js_numbers.asp