如何四舍五入到小数点后两位? [英] How do I round to 2 decimal places?
本文介绍了如何四舍五入到小数点后两位?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个带逗号的数字,例如:254,5
.我需要在,5
后面的0
,所以它看起来像254,50
.
I have a number with a comma, for example: 254,5
. I need the 0
behind the ,5
so it stands like 254,50
instead..
我正在使用它来获取号码:
I'm using this to get the number:
Math.floor(iAlt / 50) * 50;
如何将0
放在,5
后面?
推荐答案
尝试 A Number
将始终删除尾随零,因此toFixed
返回String
.
A Number
will always remove trailing zeros, so toFixed
returns a String
.
请务必注意,必须在号码上呼叫toFixed
.调用 parseFloat()
或
It's important to note that toFixed
must be called on a number. Call parseFloat()
or parseInt()
to convert a string to a number first, if required (not in this situation, but for future reference).
这篇关于如何四舍五入到小数点后两位?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文