Printing double with no trailing zeros

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

    Printing double with no trailing zeros

    Hello,

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

    Thanks,
    Michael


  • Ekkehard Morgenstern

    #2
    Re: Printing double with no trailing zeros


    Hi Michael,

    "Michael" <INERFAZE@aol.c om> schrieb im Newsbeitrag
    news:fPXsb.1720 62$RP2.157638@t wister.tampabay .rr.com...[color=blue]
    > what printf statement do I use to get variable that is double to print
    > 123.456 not 123.456000[/color]

    "%g" :-)

    I hope that helps.

    Regards,
    Ekkehard Morgenstern.


    Comment

    • Michael

      #3
      Re: Printing double with no trailing zeros

      Yes, that did it.
      Thanks,
      Michael

      "Ekkehard Morgenstern" <ekkehard.morge nstern@onlineho me.de> wrote in message
      news:bp1j80$7ja $1@online.de...[color=blue]
      >
      > Hi Michael,
      >
      > "Michael" <INERFAZE@aol.c om> schrieb im Newsbeitrag
      > news:fPXsb.1720 62$RP2.157638@t wister.tampabay .rr.com...[color=green]
      > > what printf statement do I use to get variable that is double to print
      > > 123.456 not 123.456000[/color]
      >
      > "%g" :-)
      >
      > I hope that helps.
      >
      > Regards,
      > Ekkehard Morgenstern.
      >
      >
      >[/color]


      Comment

      • Martin Ambuhl

        #4
        Re: Printing double with no trailing zeros

        Michael wrote:
        [color=blue]
        > Hello,
        >
        > what printf statement do I use to get variable that is double to print
        > 123.456 not 123.456000[/color]

        #include <stdio.h>

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

        [output]
        123.456


        --
        Martin Ambuhl

        Comment

        Working...