Decimal.TryParse doesn't parse my decimal value

被刻印的时光 ゝ 提交于 2020-01-01 07:57:38

问题


When I tried to convert something like 0.1 (from user in textbox), My value b is always false.

bool b = Decimal.TryParse("0.1", out value);

How can it be here to work?


回答1:


Too late to the party, but I was going to suggest forcing the culuture to en-US but Invariant is a better sln

decimal value;
bool b = Decimal.TryParse("0.1", NumberStyles.Any, new CultureInfo("en-US"), out value);



回答2:


Specify the culture for the parsing. Your current culture uses some different number format, probably 0,1.

This will successfully parse the string:

bool b = Decimal.TryParse("0.1", NumberStyles.Any, CultureInfo.InvariantCulture, out value);



回答3:


Use Culture in overload method



来源:https://stackoverflow.com/questions/11311570/decimal-tryparse-doesnt-parse-my-decimal-value

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!