guys. I would like to ask if there's anyway to make an int input to currency format? I have tried using
[DisplayFormat(DataFormatString = "{0:C}", ApplyFormatInEditMode = true)]
public int TotalAmount { get; set; }
but, it would show an empty
@Html.EditorFor
And if I used
[DisplayFormat(DataFormatString = "{0:F2}", ApplyFormatInEditMode = true)]
public int TotalAmount { get; set; }
It would only show 0.00
What I would like is when I input 10000, it would automatically format to
Rp. 10.000
inside the @Html.EditorFor field.
Any suggestions?
Try this:
"C" or "c" Currency Result:
[DisplayFormat(DataFormatString = "{0:C}", ApplyFormatInEditMode = true)] public decimal TotalAmount { get; set; }OR
"N" or "n" Number Result:
[DisplayFormat(DataFormatString = "{0:N}", ApplyFormatInEditMode = true)] public decimal TotalAmount { get; set; }In Entity Framework
[DataType(DataType.Currency)] public decimal TotalAmount { get; set; }EditorTemplates Example:
Create a editor template for currency
(~/Views/Shared/EditorTemplates/Currency.cshtml):Currency.cshtml
Use:
you can get more information form this and this link.