Introduction
I tried to convert a currency string ("$ 1.200,00") to decimal using c# and VS2005, I can't did it using Decimal.Parse("$ 1.200,00").
Allways the error message was "Input String was not in a correct format". But I saw
I was using the correct format.
Solution
Then I retrieved a old code using NumberStyles. I used the same code but the error still the same.
I did test the line code and when I removed the space from the currency string. Voila, it works.
This is the function.
private decimal ToDecimal(string Value)
{
if (Value.Length == 0)
return 0;
else
return Decimal.Parse(Value.Replace(" ", ""), NumberStyles.AllowThousands
| NumberStyles.AllowDecimalPoint | NumberStyles.AllowCurrencySymbol);
}
This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.
A list of licenses authors might use can be found here