Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

Using String.Format how can i ensure all numbers have commas after every 3 digits eg 23000 = "23,000" and that 0 returns "0".

String.Format("{0:n}", 0); //gives 0.00 which i dont want. I dont want any decimal places, all numbers will be integers.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
514 views
Welcome To Ask or Share your Answers For Others

1 Answer

You can do this, which I find a bit cleaner to read the intent of:

String.Format("{0:#,###0}", 0);

Example:

string.Format("{0:#,###0}", 123456789); // 123,456,789
string.Format("{0:#,###0}", 0); // 0

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...