繁体   English   中英

是否有任何函数可以在JavaScript中将值转换为数字格式?

[英]Is there any function to convert value to number format in JavaScript?

是否有在JavaScript中将值转换为数字格式的功能?

例如:10006.1056至10,006.16

就在这里。

最好的方法是创建一个可以为您的语言环境重用的NumberFormat

例如'en-US'(美国)或'en-IN'(印度)。

要设置最大精度数字,请使用选项maximumFractionDigits 如果您总是希望使用2个精度数字,例如:1必须为1.00,也使用minimumFractionDigits

var number = 10006.1056;
var nf = new Intl.NumberFormat('en-US', {
    maximumFractionDigits:2, 
    minimumFractionDigits:2
});

var formattedNumber = nf.format(number); // Will output 10,006.10

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM