'Formatting text coming from Model in MVC form
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 class="confirmationlabel">$@(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.
Solution 1:[1]
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}")
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 |
