2017-08-24 123 views
-2

我想格式化一个整数并希望将其显示为#,## 0。使用逗号格式化整数并用逗号显示值

看来,我有一个列表

<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}")] 

,但我没有得到正确的结果。

+0

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

回答

1

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

纠正我,如果我明白你的问题错了。

+0

这使得数字看起来像20.000。基本上加零,{0:N2}增加两个小数位零。我不需要我需要添加逗号。 – Tina

+0

逗号而不是点? – Fabian

+0

是的,像我想显示1234为1,234或123456为123,456 – Tina