printf() formatting - stripping zeroes, padding

M

Michal Prinke

Hello,

Here are two questions on formatting values using printf():

1. How to strip trailing zeroes from float values?
printf("%f %f", 1.777, 1.2) displays "1.777000 1.200000",
while I want to have "1.777 1.2", without loosing 6-digit
precision.

2. Is it possible to pad values with other characters than
space and zero? printf(">%5s<", "abc") displays "> abc<".
I would like to have e.g. ">##abc<" or ">--abc<".

Thank you!
 

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

Forum statistics

Threads
473,734
Messages
2,569,441
Members
44,832
Latest member
GlennSmall

Latest Threads

Top