Parse a string containing percent sign into decimal
Posted
by Sebastian Seifert
on Stack Overflow
See other posts from Stack Overflow
or by Sebastian Seifert
Published on 2010-04-15T12:59:42Z
Indexed on
2010/04/15
13:03 UTC
Read the original article
Hit count: 259
c#
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.
© Stack Overflow or respective owner