抱歉,我在 stackoverflow 上找不到工作点替换。 人们询问更换
var str = '. 950.000.000, -';
str = str.replace(/\./gi, '');
alert(parseInt(str)); // yes, it works & will output correctly
但是,当我的 'str' var 是:Rp 时,它不起作用。 950.000,- .这是我所在地区的货币格式,我想用它来做数学。我这样做,但不工作:
var str = 'Rp. 950.000, -';
str = str.replace(/\./gi, '');// i dont know, but the str values now is nothing
alert(parseInt(str)); // sure, it outputs nothing
我只想替换所有点(这样就不会打扰数学运算,因为点是数字上的小数)。
最佳答案
为什么不将所有非数字的内容替换为 \D
?
var str = 'Rp. 950.000, -';
str = str.replace(/\D/gi, '');// i dont know, but the str values now is nothing
alert(parseInt(str, 10));
关于Javascript用正则表达式替换点,但不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16867602/