Formatting decimals

  • Thread starter Thread starter C
  • Start date Start date
C

C

Hi,

I have an aspx with some labels.

I set the text of these labels to be teh return value of
some Functions that carry out some calculations.
(My Functions return decimals)

I want to format the value I write to my label so that it
is transformed for example from 87123.13 to 87,123.13

This probably quite simple but I am unsure.

Any help or direction to online help much appreciated.

Thanks,
C
 
C said:
I have an aspx with some labels.

I set the text of these labels to be teh return value of
some Functions that carry out some calculations.
(My Functions return decimals)

I want to format the value I write to my label so that it
is transformed for example from 87123.13 to 87,123.13

This probably quite simple but I am unsure.

You need the "number" format specifier, "n". For instance:

using System;

class Test
{
static void Main()
{
decimal d = 87123.13m;
Console.WriteLine ("{0:n}", d);
}
}

prints

87,123.13
(in an English culture).
 
Back
Top