Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > C Programming > Printing double with no trailing zeros

Reply
Thread Tools

Printing double with no trailing zeros

 
 
Michael
Guest
Posts: n/a
 
      11-14-2003
Hello,

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

Thanks,
Michael


 
Reply With Quote
 
 
 
 
Ekkehard Morgenstern
Guest
Posts: n/a
 
      11-14-2003

Hi Michael,

"Michael" <(E-Mail Removed)> schrieb im Newsbeitrag
news:fPXsb.172062$(E-Mail Removed) om...
> 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.


 
Reply With Quote
 
 
 
 
Michael
Guest
Posts: n/a
 
      11-14-2003
Yes, that did it.
Thanks,
Michael

"Ekkehard Morgenstern" <(E-Mail Removed)> wrote in message
news:bp1j80$7ja$(E-Mail Removed)...
>
> Hi Michael,
>
> "Michael" <(E-Mail Removed)> schrieb im Newsbeitrag
> news:fPXsb.172062$(E-Mail Removed) om...
> > 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.
>
>
>



 
Reply With Quote
 
Martin Ambuhl
Guest
Posts: n/a
 
      11-14-2003
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

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
locale.format without trailing zeros przemolicc@poczta.fm Python 5 08-22-2011 01:01 PM
format a number with leading and trailing zeros absmienk@hotmail.com Perl Misc 4 08-15-2007 01:18 PM
cannot convert parameter from 'double (double)' to 'double (__cdecl *)(double)' error Sydex C++ 12 02-17-2005 06:30 PM
Number padding... (trailing zeros'.) ThePotPlants Perl Misc 4 05-23-2004 10:19 PM
ASP IN EXCEL, trailing zeros truncated BARBARA FLOYD ASP General 1 11-11-2003 09:18 PM



Advertisments