Thursday, February 3, 2011

Numerical formatting using String.Format

Are there any codes that allow for numerical formatting of data when using string.format?

  • Loads, stick string.Format into Google :-)

    A quite good tutorial is at http://idunno.org/archive/2004/14/01/122.aspx

    From Keith
  • As Keith said above. The most common one I use is currency:

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

    Which would output £12,000.00

    From GateKiller
  • Yes, you could format it this way:

    string.Format("Format number to: {0 : #.00}", number);
    string.Format("Format date to: {0 : MM/dd/yyyy}", date);
    
    From Jon Limjap
  • There are a number. This MS site is probably the best place to look

  • Here is another very good reference that compliments what Keith mentioned.

    http://www.scribd.com/doc/2547864/msnetformattingstrings

    From DrZ
  • Taking someone else's answer and editing it and marking yourself as the person to answer is NOT COOL IMO.

    From Rob Cooper
  • Apologies. I wrote the question as I found info describing the feature in a book I was reading and I thought it would be good to add to the site so I posted the question but as I was writing the answer lots of you answered for me with some great sites so when I posted my answer it looked as if I had done exactly as robcthegeek described. Sorry if it looked that way and thanks for the great links.

    From Kievia

0 comments:

Post a Comment