Printing double with no trailing zeros

M

Michael

Hello,

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

Thanks,
Michael
 
E

Ekkehard Morgenstern

Hi Michael,

Michael said:
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.
 
M

Martin Ambuhl

Michael said:
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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
474,099
Messages
2,570,626
Members
47,237
Latest member
David123

Latest Threads

Top