在javascript / jquery中舍入到3个小数点 [英] round to 3 decimal points in javascript/jquery
本文介绍了在javascript / jquery中舍入到3个小数点的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我如何将margin_total舍入到3位小数?
How will i round margin_total to 3 decimal places?
margin_total = margin_total + parseFloat(marginObj.value);
document.getElementById('margin_total').value = margin_total;
推荐答案
使用 num.toFixed(d)
使用 d
digits <将数字转换为基数10 中该数字的字符串表示 / em>小数点后,在这种情况下,
Use num.toFixed(d)
to convert a number into the String representation of that number in base 10 with d
digits after the decimal point, in this case,
margin_total.toFixed(3);
这篇关于在javascript / jquery中舍入到3个小数点的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文