TheKingPinMirza
TheKingPinMirza

Reputation: 8912

MVC Razor view - currency formatting

I am using razor syntax. I have value e.g. 1123456 returned to my view. I would like to show it like $1,123,456 USD.

I have following line

@Model.TotalCost

How I can apply a string format on it to show a value like $1,123,456 USD?

Upvotes: 1

Views: 7950

Answers (1)

iCollect.it Ltd
iCollect.it Ltd

Reputation: 93561

You can use string.Format as you mention or, more simply, provide the currency format to the ToString() method of the property:

  @Model.TotalCost.ToString("C") USD

Upvotes: 10

Related Questions