string formatting question

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

    #1

    string formatting question

    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 = "" Why is this blank and not "0.0"
    strSpd2 = String.Format(" {0:#.#}", val2);

  • Ole

    #2
    Re: string formatting question

    Or use:

    string strSpd2 = val2.ToString(" 0.0#");

    BR,
    Ole


    "Tenacious" <CT_Taylor@yaho o.comwrote in message
    news:199c8e60-6993-4bba-ab4b-e8fcbfc42b31@s8 g2000prg.google groups.com...
    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 = "" Why is this blank and not "0.0"
    strSpd2 = String.Format(" {0:#.#}", val2);
    >

    Comment

    Working...