【问题标题】:Formatting Integer Number and displaying the value in view with comma格式化整数并用逗号在视图中显示值
【发布时间】:2017-08-25 05:28:43
【问题描述】:

我正在尝试格式化整数并希望将其显示为 #,##0。

在 View 中,我有一个列表

<input asp-for="@Model.Application[i].abc" class="form-control input-responsive" />

所以在我的应用程序模型中,我有一个属性“abc” 我想格式化。

  [Display(Name = "ABC")]
    public int abc { get; set; }

最好的方法是什么。

我尝试过使用

 [DisplayFormat(DataFormatString = "{0:N0}")]

但没有得到正确的结果。

【问题讨论】:

  • 我试过了,它只给出零 @{ string specifier = "#,##0"; var formatted= Model.Application[i].abc.ToString(specifier); }

标签: c# html asp.net-mvc-4


【解决方案1】:

你可以试试"{0:N2}0"

如果我理解错了你的问题,请纠正我。

【讨论】:

  • 这使数字看起来像 20.000。基本上加零,{0:N2} 用零加两位小数。我不需要我需要添加逗号。
  • 用逗号代替点?
  • 是的,就像我想将 1234 显示为 1,234 或 123456 为 123,456
  • 我不明白为什么 "{0:N0}" 不能解决问题... 代码:imgur.com/a/fY4dK 输出:imgur.com/a/Oi5DC
  • 值保持不变。
猜你喜欢
  • 1970-01-01
  • 2015-07-26
  • 2020-01-24
  • 1970-01-01
  • 2018-09-08
  • 2020-07-11
  • 2016-07-12
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多