Formatting decimals

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • C

    #1

    Formatting decimals

    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
  • Jon Skeet

    #2
    Re: Formatting decimals

    C <c@nospam.com > wrote:[color=blue]
    > 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.[/color]

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

    using System;

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

    prints

    87,123.13
    (in an English culture).

    --
    Jon Skeet - <skeet@pobox.co m>
    Pobox has been discontinued as a separate service, and all existing customers moved to the Fastmail platform.

    If replying to the group, please do not mail me too

    Comment

    Working...