From: Eric Hodel Date: 2005-11-16T09:19:32+09:00 Subject: Re: Quick question. On Nov 15, 2005, at 4:14 PM, hmmm wrote: > How would I format a number to simply be left-zero-padded with 2 > floating > points? > > eg. > 000.24 from .238888888 > 001.24 from 1.237777777 > 010.25 from 10.249999999 > 100.25 from 100.24999999 > > I can do: %.2f to get the 2 decimals, but it doesn't do left-zero-pad. > I can do: %03d to pad 3 digits to the left, but it doesn't trim the > decimals "%06.2f" > I can do: printf("%03d%.2f", val, (val.to_f-val.to_i)) but that always > injects > an extra 0 like so: > > 0000.24 > 0010.24 > 0100.25 > 1000.25 "%07.2f" > I have yet to find a good (useful) doc on how the format args work, > so point > me there but beware that most of the docs out there are super > useless :) printf(3) completely explains format strings. -- Eric Hodel - drbrain@segment7.net - http://segment7.net FEC2 57F1 D465 EB15 5D6E 7C11 332A 551C 796C 9F04