将字符串转换为十进制 [英] Converting string to decimal
本文介绍了将字符串转换为十进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在C#中,我试图将字符串到十进制转换。
In C#, I'm trying to convert a string to decimal.
例如,字符串为(USD 92.90)
For example, the string is "(USD 92.90)"
你会如何解析了这一点与Decimal.Parse FCN小数。
How would you parse this out as a decimal with Decimal.Parse fcn.
推荐答案
我要去假设在这里,你试图解析字符串是一个实际的货币值。
I'm going on the assumption here that the string you're trying to parse is an actual currency value.
CultureInfo c = CultureInfo.CreateSpecificCulture(CultureInfo.CurrentCulture.Name);
c.NumberFormat.CurrencyNegativePattern = 14; // From MSDN -- no enum values for this
c.NumberFormat.CurrencySymbol = "USD";
decimal d = Decimal.Parse("(USD 92.90)", NumberStyles.Currency, c);
这篇关于将字符串转换为十进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文