Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!zaphod.mps.ohio-state.edu!swrinde!cs.utexas.edu!sun-barr!newstop!male!dustbin!harry From: harry@dustbin.uk.sun.com (Harry Protoolis - Sun EHQ) Newsgroups: comp.lang.c Subject: Re: Padding floats with zeros in printf?? Message-ID: <6089@male.EBay.Sun.COM> Date: 6 Apr 91 13:29:23 GMT References: <6158@mahendo.Jpl.Nasa.Gov> Sender: news@male.EBay.Sun.COM Reply-To: harry.protoolis@uk.1.com Organization: Sun Microsystems Europe Inc Lines: 28 In article <6158@mahendo.Jpl.Nasa.Gov>, robert@nereid.jpl.nasa.gov (Robert Angelino) writes: |> 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 Try printf("%06.3f\n", 1.1324); The first part of the size specifier is a *field width*, so you need to allow for the whole output string (ie 2 (digits left of d.p) + 1 (decimal point) + 3 (digits right of d.p) = 6). Hope this helps, Harry -- (smart Internet mailers) harry.protoolis@uk.sun.com (smart JANET mailers) harry.protoolis@sun-microsystems.co.uk (dumb uucp mailers) ...!sun!sunuk!harry.protoolis 'When I give food to the poor they call me a saint. When I ask why the poor have no food they call me a communist.' - Dom Helder Camara