繁体   English   中英

如何显示不带逗号的十进制数据类型

[英]How to display decimal data type without comma

我有这个模型:

[Display(Name = "Unit Price")]
public decimal? UnitPrice { get; set; }

HTML

@Html.TextBoxFor(x => x.UnitPrice, new { @class = "form-control"})

当我提交表单时,它表示模型无效,并且该字段必须是数字:

单价字段必须为数字。

我的问题是:如何格式化小数点,以便显示点?

选择适当的Decimal.ToString()格式

另外,数字在页面上的呈现方式可能不受您的控制-不同的区域性将呈现不同的方式。

最后我找到了一个非常简单的解决方案

@Html.TextBoxFor(x => x.UnitPrice, String.Format("{0}", Model.UnitPrice.ToString().Replace(",",".")), new { @class = "form-control"})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM