formating a double value does not work as expected

Discussion in 'C++' started by Tenacious, Dec 6, 2007.

  1. Tenacious

    Tenacious Guest

    Can anyone tell me why strSpd2 in the example below ends up being a
    blank string when formatting a zero value? It would seem to me that
    strSpd2 should end up being "0.0"

    double val1 = 14.38009
    double val2 = 0.0;
    string strSpd1 = "";
    string strSpd2 = "";

    // This formats correctly. strSpd1 = "14.4"
    strSpd1 = String.Format("{0:##.#}", val1);

    // This does not format. strSpd2 = ""
    strSpd2 = String.Format("{0:#.#}", val2);
    Tenacious, Dec 6, 2007
    #1
    1. Advertising

  2. Tenacious

    Tenacious Guest

    On Dec 6, 9:33 am, Tenacious <> wrote:
    > Can anyone tell me why strSpd2 in the example below ends up being a
    > blank string when formatting a zero value? It would seem to me that
    > strSpd2 should end up being "0.0"
    >
    > double val1 = 14.38009
    > double val2 = 0.0;
    > string strSpd1 = "";
    > string strSpd2 = "";
    >
    > // This formats correctly. strSpd1 = "14.4"
    > strSpd1 = String.Format("{0:##.#}", val1);
    >
    > // This does not format. strSpd2 = ""
    > strSpd2 = String.Format("{0:#.#}", val2);


    Sorry, I put this in the wrong group.
    Tenacious, Dec 6, 2007
    #2
    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. Brian Takita
    Replies:
    3
    Views:
    702
    Patrick Olurotimi Ige
    May 12, 2005
  2. Sydex
    Replies:
    12
    Views:
    6,485
    Victor Bazarov
    Feb 17, 2005
  3. =?Utf-8?B?dmluZWV0YmF0dGE=?=

    IsInRole does not work as expected

    =?Utf-8?B?dmluZWV0YmF0dGE=?=, Jan 6, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    364
    =?Utf-8?B?dmluZWV0YmF0dGE=?=
    Jan 6, 2007
  4. Salvador Sanjuan

    # sign does not work as expected form irb

    Salvador Sanjuan, Aug 26, 2009, in forum: Ruby
    Replies:
    14
    Views:
    181
    Salvador Sanjuan
    Aug 28, 2009
  5. Ishmael
    Replies:
    12
    Views:
    204
    Ishmael
    Jan 17, 2007
Loading...

Share This Page