Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

remove leading zero in float formatted output

0 views
Skip to first unread message

migurus

unread,
Feb 18, 2010, 9:03:14 PM2/18/10
to
Is it possible to print a float or double and omit the leading zero in
the following fasion:
.123

Code:
float f = 0.1;
printf("%.1f\n", f);
result:
0.1

Is there a trick with format string to get
.1
printed instead?

Regard
Mi

Paul N

unread,
Feb 19, 2010, 7:10:21 AM2/19/10
to

I don't think you can do it just by changing the format string, as the
standard says "If a decimal-point character appears, at least one
digit appears before it.". Possibly it might help to print the string
to a buffer, using sprintf, and then inspect that before printing it.

Hope that helps.
Paul.

0 new messages