Convert decimal separator


I want to change the decimal separator in a variable.

I want to check if the the variable contains a dot (.). If it does it must delete the dot.
After that i want to check the variable for commas, if there is a comma, it must be changed to a dot.
ex. 10.508,75 --> 10508.75


Where will you use the result? is this a text to begin with or is it a decimal type? if it is a string and you want to convert to decimal, you can simply use the TryParse function with both approaches, the one that works first is the right one

The answer provided by @bcorrea is probably your best bet for parsing monetary amounts. I wanted to add a couple of general tips on top of that:

Both the String.Replace and the Regex.Replace functions work whether or not the string contains the specified string or pattern so you don’t need the If statements whenever you’re replacing things.

Secondly, since you’re using the Regex.Replace and not the String.Replace the search pattern is evaluated as a regular expression which means that “.” will match every single character since that’s the wildcard character.

This topic was automatically closed 3 days after the last reply. New replies are no longer allowed.