0

First of all excuse me for this stupid question. This is something with that I am stuck and didn't get anything around.

I am in need of decimal format where if value is something like-

15000.45 should go to => 15,000
150000.44 should go to => 150,000

Note- I want to eliminate points value after period (.)

I've gone through input mask-

http://digitalbush.com/projects/masked-input-plugin/ but couldn't find any helper mask.

Another resource I tried-

Convert decimal currency to comma separated value

But they are replacing point value replaced by comma, i.e. if value is something 15000.34 then it converts it to 15000,34

I also tried it giving custom format as- value.ToString("0,00") but doesn't help.

Please assist!

Community
  • 1
  • 1
Manoz
  • 6,507
  • 13
  • 68
  • 114
  • 2
    Take a look at the MSDN docs here: https://msdn.microsoft.com/en-us/library/fzeeb5cd(v=vs.110).aspx. value.ToString("C") will give you what you want – Michael B Jan 05 '16 at 09:21
  • 2
    You want to do two things: omit decimals and add a thousand separator. What do you want to happen with the decimals? What should happen with `1000.99`? Do you want to round, and if so, which rounding do you want to apply, or do you want to truncate? After deciding that, displaying with thousand separator is trivial. Anyway, see [duplicate](http://stackoverflow.com/questions/105770/net-string-format-to-add-commas-in-thousands-place-for-a-number): `{0:n0}`. – CodeCaster Jan 05 '16 at 09:24

1 Answers1

2
decimal d = 15000.45m;

d.ToString("#,#"); //15,000
// or clearer arguably:
d.ToString("N0"); //15,000

And it will work for millions:

1234567.45m -> 1,234,567;
weston
  • 54,145
  • 21
  • 145
  • 203