NoWar
NoWar

Reputation: 37633

How to display decimal data type without comma

I have this model:

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

HTML:

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

When I submit the form, it says that model is invalid and the field must be a number:

The field Unit Price must be a number.

My question is: How I can format decimal so it will be shown with point?

Upvotes: 0

Views: 2570

Answers (2)

NoWar
NoWar

Reputation: 37633

Finally I found a very simple solution

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

Upvotes: 1

48klocs
48klocs

Reputation: 6103

Pick an appropriate Decimal.ToString() format.

Also, the way that the number gets rendered on the page may be out of your control - different cultures will render different ways.

Upvotes: 2

Related Questions