如何用点和逗号解析数字

jos*_*b94 1 javascript precision jquery decimal web

我收到一个字符串;

1.234.567,89

我要1234567.89

逗号是十进制分隔符。点是千,百万分隔符

我想把它当作一个数字。

我尝试替换,但只适用于第一个“.”。和 parseFloat。我也尝试了一些在这里找到的正则表达式,但对我不起作用

我要这个;

    var numberAsString= '1.234.567,89';
    //Step to clean string and conver to a number to compare (numberAsString => numberCleaned)
    if (numberCleaned> 1000000) {alert("greater than 1 million");}
Run Code Online (Sandbox Code Playgroud)

任何的想法?(对不起,如果这是一个新手问题,但我在几个小时内没有找到任何解决方案......)

brk*_*brk 5

你可以用replaceg

const val = '1.234.567,89'.replace(/\./gi, '').replace(/,/, '.');
console.log(val)
console.log(typeof parseFloat(val))
Run Code Online (Sandbox Code Playgroud)