Home > Back-end >  Formatting text coming from Model in MVC form
Formatting text coming from Model in MVC form

Time:04-20

I want to add figures together from model and display them formatted like a dollar amount.

Here is the code I'm attempting to format:

<td >$@(Model.Amount   Model.FeeAmount) </td>

How do I go about formatting the output to be in $0.00 format? I tried adding tostring to the end but it didn't recognize it. Right now, if it is a whole dollar, it comes out without the .00 at the end.

CodePudding user response:

There are quite some parenthesis to get set correctly.
The formats below should do it.

Either call ToString

$@((Model.Amount   Model.FeeAmount).ToString("0.00"))

Or use string interpolation (represented by the second $ here below)

$@($"{(Model.Amount   Model.FeeAmount):0.00}")
  • Related