簡體   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