数据注释进行舍入

发布于 2024-12-15 22:34:41 字数 353 浏览 2 评论 0原文

您好,我的一个模型中有一个属性:

[Required(ErrorMessage = "Total (Exc. GST) is a required field.")]
[Display(Name = "Total (Exc. GST):")]
[DataType(DataType.Currency)]
public virtual decimal TotalExcludingGst { get; set; }

它上面有货币注释。

问题是,当验证期间发生问题时,它会显示 4 个小数位,例如

57500.0000

是否有无论如何添加一个注释,使验证消息中的这 2 个小数位?

Hi I have a property in one of my models which is:

[Required(ErrorMessage = "Total (Exc. GST) is a required field.")]
[Display(Name = "Total (Exc. GST):")]
[DataType(DataType.Currency)]
public virtual decimal TotalExcludingGst { get; set; }

It has the currency annotation above it.

The problem is when an issue with it happened during validation it displays with 4 decimal places like

57500.0000

Is there anyway to add an annotation that will make this 2 decimal places in the validation messages?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

花海 2024-12-22 22:34:41

添加

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

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

Add

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

or

[DisplayFormat(DataFormatString = "{0:C}")]
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文