Printing double with no trailing zeros

Discussion in 'C Programming' started by Michael, Nov 14, 2003.

  1. Michael

    Michael Guest

    Hello,

    what printf statement do I use to get variable that is double to print
    123.456 not 123.456000

    Thanks,
    Michael
     
    Michael, Nov 14, 2003
    #1
    1. Advertising

  2. Hi Michael,

    "Michael" <> schrieb im Newsbeitrag
    news:fPXsb.172062$...
    > what printf statement do I use to get variable that is double to print
    > 123.456 not 123.456000


    "%g" :)

    I hope that helps.

    Regards,
    Ekkehard Morgenstern.
     
    Ekkehard Morgenstern, Nov 14, 2003
    #2
    1. Advertising

  3. Michael

    Michael Guest

    Yes, that did it.
    Thanks,
    Michael

    "Ekkehard Morgenstern" <> wrote in message
    news:bp1j80$7ja$...
    >
    > Hi Michael,
    >
    > "Michael" <> schrieb im Newsbeitrag
    > news:fPXsb.172062$...
    > > what printf statement do I use to get variable that is double to print
    > > 123.456 not 123.456000

    >
    > "%g" :)
    >
    > I hope that helps.
    >
    > Regards,
    > Ekkehard Morgenstern.
    >
    >
    >
     
    Michael, Nov 14, 2003
    #3
  4. Michael wrote:

    > Hello,
    >
    > what printf statement do I use to get variable that is double to print
    > 123.456 not 123.456000


    #include <stdio.h>

    int main(void)
    {
    double x = 123.456;
    printf("%.3f\n", x);
    return 0;
    }

    [output]
    123.456


    --
    Martin Ambuhl
     
    Martin Ambuhl, Nov 14, 2003
    #4
    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. Replies:
    5
    Views:
    320
    Peter Otten
    Aug 22, 2011
  2. BARBARA FLOYD

    ASP IN EXCEL, trailing zeros truncated

    BARBARA FLOYD, Nov 11, 2003, in forum: ASP General
    Replies:
    1
    Views:
    170
    Ray at
    Nov 11, 2003
  3. ThePotPlants

    Number padding... (trailing zeros'.)

    ThePotPlants, May 23, 2004, in forum: Perl Misc
    Replies:
    4
    Views:
    427
    ThePotPlants
    May 23, 2004
  4. Replies:
    4
    Views:
    125
  5. Replies:
    4
    Views:
    106
    PyNoob
    Jun 27, 2013
Loading...

Share This Page