开发者

Javascript Decimals

How can I convert a integer type to a double/float type so it shows decimal points? For instance if I want to convert a number to a money format:

5 would turn into 5.00 4.3 would turn into 4.30

Doe开发者_运维技巧s javascript have something I can use to do this kind of conversion?


You want toFixed:

var a = 5;
a.toFixed(2); // '5.00'
4.3.toFixed(2); // '4.30'


You can use toFixed(n), where n is the number of decimal places.

5 .toFixed(2);
//-> "5.00"

4.3 .toFixed(2);
//-> "4.30"
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜