我有2,299.00
一个字符串,我试图解析它的数字.我尝试使用parseFloat
,结果是2.我猜逗号是问题,但我怎么能以正确的方式解决这个问题呢?只需删除逗号?
var x = parseFloat("2,299.00")
alert(x);
Run Code Online (Sandbox Code Playgroud)
我有字符串"722,311.75",我想将其转换为722,311.75(货币格式).以下代码不起作用.
var str = "722,311.75";
var nr = parseFloat(str, 10).toFixed(2);
console.log(nr); // Returns 722.00
Run Code Online (Sandbox Code Playgroud)
我怎么能这样做?