Reputation: 99
I have some "double" values in a gridview on an aspx page. I need to use comma-styling in these values like:
original value = 1986.05 required value = 19,86.05
original value = 51986.05 required value = 5,19,86.05
I am using the following code for this:
e.Row.Cells[6].Text = String.Format("{0:##,##,##.##}", Convert.ToDouble(e.Row.Cells[6].Text));
It is showing the value as 1,986.05 but I need it as 19,86.05
Please help!
Upvotes: 2
Views: 130
Reputation: 16433
You can use a custom CultureInfo
with 2-digit number grouping to achieve this:
CultureInfo culture = new CultureInfo(string.Empty, true)
{
NumberFormat = { NumberGroupSizes = new int[] { 2 } }
};
Console.WriteLine((1986.05).ToString("N", culture));
Output:
19,86.05
The documentation set for NumberGroupSizes
is available here that describes this.
In your code you could implement it like:
CultureInfo culture = new CultureInfo(string.Empty, true)
{
NumberFormat = { NumberGroupSizes = new int[] { 2 } }
};
e.Row.Cells[6].Text = Convert.ToDouble(e.Row.Cells[6].Text).ToString("N", culture);
Upvotes: 8