Padding floats with zeros in printf??

Robert Angelino robert at nereid.jpl.nasa.gov
Sat Apr 6 07:41:20 AEST 1991


background: I'm running SunOS 4.1 on a SPARC using the Sun
	    C compiler.

I'm doing something like so:

	printf("%02.3f\n",1.1324);

and I'm getting this:

	1.132

I want something like

	01.132

The book "C A Reference Manual" by Steele & Harbison say that the
following should work:
	printf("%02.3f\n",1.1324); OR
	printf("%#02.3f\n",1.1324); OR
	printf("%02.3g\n",1.1324); OR
	printf("%#02.3g\n",1.1324);

Now, I've tried all of these (including the "hammer") and nothing seems
to work.  If the book says it should work then the compiler is not doing
it's job correctly.  Does anyone know how to get around this using this
compiler???

Please e-mail directly.

thanks in advance


-- 
    -     ------       -                              Robert Angelino
   | |   | ----  \    | |                             ms T-1704L
   | |   | |   \ |    | |                             4800 Oak Grove Drive
   | |   | | --  |    | |                             Pasadena, CA 91109
---| |   | | \__/     | |___                          robert at triton.jpl.nasa.gov
\____|et |_|ropulsion |_____\aboratory                (818) 354-9574



More information about the Comp.lang.c mailing list