Parse a string containing percent sign into decimal
- by Sebastian Seifert
I have a simple string containing VAT-percantage value that needs to be stored in a decimal. The string looks like this: "19.00%". When I use the decimal.Parse() methode I always get an FormatException.
Code looks like this
NumberFormatInfo nfi = new NumberFormatInfo()
{
PercentDecimalSeparator = ".",
PercentSymbol = "%"
};
decimal.Parse("19.00%",NumberStyles.Any, nfi);
I know, that it would be possible (in the excample above) to simply remove the %-char from the string and then parse. But isn't there a solution to use built in parsing, which can be used without testing the string for the type of number the user typed in.