gpt4 book ai didi

asp.net-mvc - asp.net mvc : thousand separator for int value

转载 作者:行者123 更新时间:2023-12-04 10:51:00 26 4
gpt4 key购买 nike

我的数据库中有一个价格字段为整数
现在我通过我的模型来查看和显示价格:

@Html.DisplayFor(modelItem => item.price)

我怎样才能看到千位分隔符的价格?
tnx

最佳答案

申请 DisplayFormat属性到您的模型属性:

[DisplayFormat(DataFormatString = "{0:N2}")]
public decimal Cost { get; set; }

然后由 ModelBinder 为您完成格式化,而您不必记住在每个单独的 View 中进行格式化。

关于asp.net-mvc - asp.net mvc : thousand separator for int value,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24120900/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com