Formatting Strings

Discussion in 'ASP .Net' started by Guadala Harry, Oct 28, 2004.

  1. So far into my forray into .NET I have not had to format strings... until
    now. I have a stored procedure that returns a decimal value that looks like
    this: 12345.1234.

    I would like to format it to look like this: $12,345.12

    The formatted value should be rounded to two decimal places.

    The value to be formatted currently shows up in my code in a DataRow like
    this: Convert.ToString(DR_Items["Price"])

    Thanks.
     
    Guadala Harry, Oct 28, 2004
    #1
    1. Advertising

  2. Guadala Harry wrote:
    > So far into my forray into .NET I have not had to format strings... until
    > now. I have a stored procedure that returns a decimal value that looks like
    > this: 12345.1234.
    >
    > I would like to format it to look like this: $12,345.12
    >
    > The formatted value should be rounded to two decimal places.
    >
    > The value to be formatted currently shows up in my code in a DataRow like
    > this: Convert.ToString(DR_Items["Price"])


    Look into String.Format(). There are a number of format specifiers that
    you can use that do specific formatting. You'd likely want the currency
    formatting here:

    string formattedResults = string.Format("{0:c}", DR_Items["Price"]);

    hth

    --

    Scott Mitchell

    http://www.4GuysFromRolla.com

    * When you think ASP.NET, think 4GuysFromRolla.com!
     
    Scott Mitchell [MVP], Oct 28, 2004
    #2
    1. Advertising

  3. Perfect - thanks!


    "Scott Mitchell [MVP]" <> wrote in message
    news:%4bgd.1708$...
    > Guadala Harry wrote:
    > > So far into my forray into .NET I have not had to format strings...

    until
    > > now. I have a stored procedure that returns a decimal value that looks

    like
    > > this: 12345.1234.
    > >
    > > I would like to format it to look like this: $12,345.12
    > >
    > > The formatted value should be rounded to two decimal places.
    > >
    > > The value to be formatted currently shows up in my code in a DataRow

    like
    > > this: Convert.ToString(DR_Items["Price"])

    >
    > Look into String.Format(). There are a number of format specifiers that
    > you can use that do specific formatting. You'd likely want the currency
    > formatting here:
    >
    > string formattedResults = string.Format("{0:c}", DR_Items["Price"]);
    >
    > hth
    >
    > --
    >
    > Scott Mitchell
    >
    > http://www.4GuysFromRolla.com
    >
    > * When you think ASP.NET, think 4GuysFromRolla.com!
     
    Guadala Harry, Oct 28, 2004
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Perecli Manole

    formatting strings

    Perecli Manole, Oct 23, 2003, in forum: ASP .Net
    Replies:
    3
    Views:
    560
    Bret Mulvey [MS]
    Oct 24, 2003
  2. Joona I Palaste

    Question on formatting Strings

    Joona I Palaste, Oct 19, 2003, in forum: Java
    Replies:
    3
    Views:
    398
    Paul Lutus
    Oct 20, 2003
  3. Rick

    formatting strings

    Rick, Oct 16, 2003, in forum: C Programming
    Replies:
    10
    Views:
    635
    Irrwahn Grausewitz
    Oct 17, 2003
  4. Steve Holden

    Enumerating formatting strings

    Steve Holden, Apr 18, 2005, in forum: Python
    Replies:
    14
    Views:
    520
    Michael Spencer
    Apr 21, 2005
  5. Ben

    Strings, Strings and Damned Strings

    Ben, Jun 22, 2006, in forum: C Programming
    Replies:
    14
    Views:
    788
    Malcolm
    Jun 24, 2006
Loading...

Share This Page