+ 3

var num1=0.1, num2=0.2, num3=0.3; console.log(num1 + num2 == num3);

If answer will be false, Why???

27th May 2020, 3:24 AM
Jayaprakash
Jayaprakash - avatar
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
27th May 2020, 3:34 AM
NoOr
NoOr - avatar
+ 2
Thank you @Noor Mohammad
27th May 2020, 3:54 AM
Jayaprakash
Jayaprakash - avatar