Let's say I have a string, and that string's value is an amount of money, localized. By localized, I mean that if the country may use commas instead of decimal points, for example. (That's just one localization difference I know if.)
How can I parse one of these strings into their decimals numeric equivalents? Will decimal.TryParse() recognize localized formatting? How do I specify the CultureInfo with TryParse()?
Here is an example of decimal.TryParse with a specified CultureInfo (Swedish in this case):
string s = "10,95";
decimal d;
if (decimal.TryParse(s, NumberStyles.Number, CultureInfo.GetCultureInfo("sv-SE"),out d))
{
Console.WriteLine(d);
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With