javascript - 一美元的上限 [英] javascript - ceiling of a dollar amount
本文介绍了javascript - 一美元的上限的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
3.19 = 3.19
3.191 = 3.20
3.00000001 = 3.01
解决方案
num = Math.ceil(num * 100 )/ 100;
虽然由于浮点数的表示方式,您可能不会得到一个干净的数字,小数点后两位。出于显示的目的,总是做 num.toFixed(2)
。
So I am adding and subtracting floats in javascript, and I need to know how to always take the ceiling of any number that has more than 3 decimal places. For example:
3.19 = 3.19
3.191 = 3.20
3.00000001 = 3.01
解决方案
num = Math.ceil(num * 100) / 100;
Though, due to the way floats are represented, you may not get a clean number that's to two decimal places. For display purposes, always do num.toFixed(2)
.
这篇关于javascript - 一美元的上限的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文