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

I have a variable of type Long i.e.

long quantity=1000;

I want to display it like 1,000 in Grid (Must need commas)

How do i achieve this?

I am using a Telerik Grid and I am binding the data as follows:

columns.Bound(tempProductList => tempProductList.tempProductListQuantity) .Title("Quantity")
See Question&Answers more detail:os

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

1 Answer

Here you have a list of all the standard numeric formats. I think "N" is the one you want.

long l = 1234;
string s  = l.ToString("N0"); //gives "1,234"

The "0" after the format specifier is the number of desired decimal places (usually 2 by default).

Note that this version is culture-sensitive, i.e., in my country, we use dots (".") as thousand separators, so the actual returned value will be "1.234" instead of the "1,234". If this is desired behaviour, just leave it as is, but if you need to use commas always, then you should specify a culture as a parameter to the ToString method, like

l.ToString("N0", CultureInfo.InvariantCulture); //always return "1,234"

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