+ 3
var num1=0.1, num2=0.2, num3=0.3; console.log(num1 + num2 == num3);
If answer will be false, Why???
2 Answers
+ 9
You can consider it as a error in Js đ
. Because if you try to add any decimal value then Js return the sixteen more digits or so after the decimal point .
if you try this
var num1 = 0.1;
var num 2 = 0.2;
console.log(num1+num2)
the answer will be 0.30000000000004
which is certainly not equal to 0.3
thats why the answer is false .
you can use toFixed method to overcome the error
Thanks for reading ..
If you understood please upvote :D
+ 2
Thank you @Noor Mohammad