Click here to Skip to main content
15,886,873 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello there,

I just want to know, after the sum of two numbers like 1000 + 5000 = 6000, Here after the sum I want to add comma like 6,000 how to do this automatically ?

OR in caseif there is a value like 10000 or 100000 here it should get the output like this :

10,000 & 1,00,000 automatically.

What I have tried:

Nothing tried as it is new for me.
Posted
Updated 14-Nov-22 21:30pm

You use: Standard numeric format strings | Microsoft Learn[^] or more specifically: Custom numeric format strings | Microsoft Learn[^]
There are three (3) ways:
C#
var formatted = string.Format("{0:N0}", value);

the second:
C#
var formatted = value.ToString("{0:N0}");

and the third:
C#
var formatted = "{value:N0}";
 
Share this answer
 
v3
You don't add commas to numbers, you add commas to strings when your prepare a number for presentation to the user. And even then, you don't "just add them", as the position of commas as numeric separators depends on the users culture settings. For example:
12,34,567.89   Indian format
1,234,567.89   English and American format
1 234 567,89   Canadian format
1.234.567,89   Italian format
But there are other combinations: Decimal and Thousands Separators (International Language Environments Guide)[^]

Basically, you shouldn't assume any particular numbering format: you could confuse the issue quite considerably!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900