MVC Entity Framework Integer Thousand Separator

1.7k Views Asked by At

This is probably a very simple question but i cannot work it out and i cannot find it anywhere.

I have a model with the following property:

[DisplayFormat(DataFormatString ="{0:0.##}")]
public decimal Jan { get; set; }

As you can see, it is a simple decimal value which I have used the DisplayFormat annotation on in order to remove the decimal places, if the decimal places are .00.

However, I now need to edit this DisplayFormat in order to include thousand and million separators as commas.

Does anybody know how i would go about this please?

Many Thanks In Advance,

2

There are 2 best solutions below

1
On BEST ANSWER
[DisplayFormat(DataFormatString = "{0:N2}")]
public decimal Jan { get; set; }
3
On

I don't think your doing this quite right. Check out this article on MSDN https://msdn.microsoft.com/en-us/library/bb688127.aspx. Specifically the section "Number Formatting in .net." Currency formatting is a localization concern. You want to use the currency formatting of .net to give you the correct separators