Is %f formatting broken?

sprintf ("%d days %02d:%02d:%02.6f",@DD,@hh,@mm,@ss)
produces:
537 days 22:05:10.081386 until Teddy gets his learner’s permit
537 days 22:05:9.081456 until Teddy gets his learner’s permit

I intended for the seconds to be right-justified and zero-filled.

Hi,

sprintf (“%d days %02d:%02d:%02.6f”,@DD,@hh,@mm,@ss)
produces:
537 days 22:05:10.081386 until Teddy gets his learner’s permit
537 days 22:05:9.081456 until Teddy gets his learner’s permit

I intended for the seconds to be right-justified and zero-filled.

But that’s how printf(3) works.

% cat c.c
main(){
printf(“%d days %02d:%02d:%02.6f\n”,537,22,5,9.09);
}
% gcc c.c
% a.out
537 days 22:05:9.090000

						matz.
···

In message “Is %f formatting broken?” on 02/11/27, “Ted” ted@datacomm.com writes:

sprintf (“%d days %02d:%02d:%02.6f”,@DD,@hh,@mm,@ss)
produces:
537 days 22:05:10.081386 until Teddy gets his learner’s permit
537 days 22:05:9.081456 until Teddy gets his learner’s permit

I intended for the seconds to be right-justified and zero-filled.

The ‘.6’ part is the number of digits past the decimal point.
The ‘02’ is the width of the entire field.

Thus what you’re wanting is:

%09.6f

% ruby -e ‘printf “x%09.6fx\n”, 9.081456’
x09.081456x

cheers,

···


Iain.