I know this is the silliest question to ask. But really I’m having trouble to convert price(string) to decimal. Here is what I have tried
string s = "123.45";
decimal d = decimal.Parse(s, NumberStyles.AllowCurrencySymbol | NumberStyles.AllowThousands | NumberStyles.AllowDecimalPoint);
But I’m getting Format exception
Also tried
decimal num;
bool pass = decimal.TryParse("2.85", out num);
num comes out as 0.
Any help will be greatly appreciated.
Try specifying an invariant culture in which
.is the decimal separator:The
Parsemethod uses the current thread culture to parse numbers. So if you are using some culture in which.is not the decimal separator (such asfr-FRfor example) it won’t work as it would expect the number to be123,45for instance.