c# - 从 .ToString ("{0:C}") 格式的数字中删除 $

标签 c# string-formatting

基本上我是这样格式化数字的

@String.Format("{0:C}", Model.Price)

结果是 $2,320,000.00

然而,我想要的结果是 2,320,000.00,只是没有 $。我怎样才能做到这一点,同时仍然利用 .nets 本地化处理?

编辑

如果我想要改变我的类,那么当有人试图获取 Price 时,他会得到这种格式化的价格。这是我的课

public class Listing : DomainObject
{   
    public decimal Price { get; set; }
    public decimal Commission { get; set; }
}

最佳答案

使用 N 而不是 C 作为您的 format specifier :

@String.Format("{0:N}", Model.Price)

"C" or "c" Currency Result: A currency value.

123.456 ("C", en-US) -> $123.46

"N" or "n" Number Result: Integral and decimal digits, group separators, and a decimal

1234.567 ("N", en-US) -> 1,234.57

即你得到一个货币符号是因为你要求一个。

关于c# - 从 .ToString ("{0:C}") 格式的数字中删除 $,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17541307/

相关文章:

c# - 未找到时区区域

c# - Log4Net - 为级别类型设置 conversionPattern

c# - 如何使用 GetType 访问 C# 中派生类的方法/属性?

python - 我如何正确处理多维 numpy 数组

printf() 能否为值 (-0.5) 生成 "-.5"?

c# - 格式化不带前导零的 TimeSpan 天数时出现 FormatException

python - 打印十六进制字符串

c# - 需要多个声音输出到多个扬声器

c# - WPF C# : MVVM - Passing on the Sudoku from ViewModel -> View

c# - 在字符串中使用变量