Extra leading zeros when printing float using printf?

Posted by shoosh on Stack Overflow See other posts from Stack Overflow or by shoosh
Published on 2010-03-21T08:27:29Z Indexed on 2010/03/21 8:31 UTC
Read the original article Hit count: 369

Filed under:
|
|
|

I'd like to be able to write a time string that looks like this: 1:04:02.1 hours using printf.
When I try to write something like this:

printf("%d:%02d:%02.1f hours\n", 1, 4, 2.123456);

I get:

1:04:2.1 hours

Is it possible to add leading zeros to a float formatting?

© Stack Overflow or respective owner

Related posts about c++

Related posts about printf