From: Lloyd Zusman Date: 2005-11-16T09:29:11+09:00 Subject: Re: Quick question. hmmm writes: > 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 > > 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 > > 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 :) Try this: printf("%07.2f", val) The "7" is the total field width, including the decimal point. The "2" represents the number of decimal places. The leading "0" means to zero-pad. -- Lloyd Zusman ljz@asfast.com God bless you.