remove leading zero in float formatted output

M

migurus

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
 
P

Paul N

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?

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.
 

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
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top