0

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,

DaRoGa
  • 2,196
  • 8
  • 34
  • 62

2 Answers2

0

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

Fran
  • 6,440
  • 1
  • 23
  • 35
  • This is not currency though. It is just standard numbers so there should be a way for me to do it as i have done the decimal places as there is no localization issue – DaRoGa May 05 '16 at 13:19
  • http://stackoverflow.com/questions/105770/net-string-format-to-add-commas-in-thousands-place-for-a-number – Fran May 05 '16 at 13:23
  • I found that question also, however, i couldnt work out how to combine it with my other DisplayFormat. any ideas? – DaRoGa May 05 '16 at 13:24
0
[DisplayFormat(DataFormatString = "{0:N2}")]
public decimal Jan { get; set; }
Scott
  • 13,735
  • 20
  • 94
  • 152
  • Wont this do just the thousand seperator and not maintain my decimal place format? do you know how i would combine the two? – DaRoGa May 05 '16 at 13:26