I have found a regex on stackoverflow to add a ',' or '.' after every third number depending on your language.
(d)(?=(ddd)+(?!d))
The problem is that it also happens when we reach the decimal point like with for example:
5487445.46878
The result of that with the following code (and regex) is:
return number.replace(/(d)(?=(ddd)+(?!d))/g, "$1,");
Which results in:
5,487,445.46,878
I'm using this regex when I'm converting a number depending on your language. In Dutch for example a comma is used as a seperator, so there I do the following:
return number.replace(/(d)(?=(ddd)+(?!d))/g, "$1.")
Which results in
5.487.445,46.878
These of course need to become:
5,487,445.46878
and
5.487.445,4687
Does anybody know where I need to update the regex to ignore the decimal point?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…