Regular expression for processing European numbers and vice versa

I am trying to find a simple way of working with numbers in my app that works with European numbers, which is turning out to be more complicated than I thought. According to the European number format, thousand separators are denoted by a period (.) and decimals places in comma (,), and the number operators in Javascript gets confused, and try to interpret 1000 (writen as 1.000) as 1, and the users, who are Europeans, get confused by regular number expressions…Currently I am using a simple regular expression to remove the period from the number so it renders properly

(/\./g, '')

But as you can imagine, this solution only works if there are no decimal places. What would be a regular expression to remove any thousand separators, if they exist, AND if there is a separator at in front of the last two digits, replace it as a decimal separator, and then convert and display the number back to the user in its original format?

90 thoughts on “Regular expression for processing European numbers and vice versa”

Leave a Comment