Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

asp.net mvc: thousand separator for int value

I have a price field in my database as integer now i pass my model to view and show the price in view:

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

How can i put thousand separator for price in view? tnx

like image 235
Morteza Avatar asked Jun 09 '14 13:06

Morteza


2 Answers

Apply the DisplayFormat attribute to your model property:

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

Then the formatting is done by the ModelBinder for you instead of you having to remember to do it in each individual view.

like image 139
PhilPursglove Avatar answered Sep 20 '22 18:09

PhilPursglove


Here ...

@Html.DisplayFor(modelItem => item.price.ToString("n2"))
like image 32
Amin Saqi Avatar answered Sep 19 '22 18:09

Amin Saqi