c# - 将字符串转换为十进制

标签 c#

在 C# 中,我正在尝试将字符串转换为十进制数。

例如字符串为“(USD 92.90)”

您如何使用 Decimal.Parse fcn 将其解析为小数。

最佳答案

我在这里假设您要解析的字符串是实际货币值。

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);

关于c# - 将字符串转换为十进制,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1636985/

相关文章:

c# - 如何编写从接口(interface)到另一种类型的隐式转换?

c# - Flyout 导致应用程序崩溃 [Windows 10] C# XAML

c# - 将 ContextMenu 绑定(bind)到 Datagrid 列

c# - 使用给定的起点和终点从 html 中分离出一段数据

c# - 将任务作为参数传递

c# - Windows Phone 8.1/Windows 8.1如何设置http客户端请求操作超时

C# IOptions 无法将我的对象隐式转换为接口(interface)以将其注入(inject)我的服务 AddSingleton

c# - 从 WP7 中的网站解析数据

c# - "Invalid provider type specified"尝试加载证书私钥时出现CryptographicException

c# - 从 System.Windows.Media.Geometry 获取坐标列表