Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

decimal.TryParse returns false

The input string in textbox is, say, $10.00 . I call

decimal result;
var a = decimal.TryParse(text, NumberStyles.AllowCurrencySymbol, cultureInfo, out result);

cultureInfo is known (en-US). Why does decimal.tryParse returns false?

Thank you.

like image 848
Igor S Avatar asked Dec 16 '22 10:12

Igor S


1 Answers

The problem is you've allowed the currency symbol itself, but you've omitted other properties that are required to parse it correctly (decimal point, for example.) What you really want is NumberStyles.Currency:

decimal.TryParse("$10.00", NumberStyles.Currency, cultureInfo, out result);
like image 65
dlev Avatar answered Dec 24 '22 08:12

dlev