[Javascript] How to deal with floating number
2020-12-13 02:40
标签:cal pre strong another other result oat class answer What‘s your expect of the output?: The answer is ‘false‘. Because: Therefore if we do calculation on Frontend: The result is not correct. The solution for this: [Javascript] How to deal with floating number 标签:cal pre strong another other result oat class answer 原文地址:https://www.cnblogs.com/Answer1215/p/11047804.htmlconsole.log(0.1 + 0.2 === 0.3);
0.1+ 0.2 // 0.30000000000000004
const price = 9.33;
const quantity = 3;
console.log(price * quantity); // 27.990000000000002
const anotherPrice = 9.33 * 100;
const anotherQuantity = 3;
console.log((anotherPrice * anotherQuantity) / 100); // 27.99
上一篇:python常用模块(二)
下一篇:Python3使运行暂停的方法
文章标题:[Javascript] How to deal with floating number
文章链接:http://soscw.com/essay/26043.html