David --- Senior Programmer Analyst --- Wgo Wagner wrote: > I am trying to get .15 and end up with 0.15. I have tried a number of combinations > of sprintf and %f. > > sprintf "%.2f" > sprintf "%2.2f" > sprintf "% .2f" > sprintf "% 2.f" > > and I always get a 0.15. > > Do I just remove with a regex or am I missing something? > > Running on w2k and AS 5.6.0 Build 623. >
No, you have to remove it with a regex. Perl's sprintf uses the C sprintf for floating-point formatting. A format of "%n.mf" uses 'n' for a /minimum/ field width, but it will still use enough space to give you at least one figure before the decimal point. The 'm' is the number of decimal places, so sprintf "%0.0f", 0.15 will give you '0' :) A proper solution depends on what you want in general. If you just want to lose any leading zeroes then it's real simple: (my $string = sprintf "%.2f", 0.15) =~ s/^0+//; but you'll still get -0.15. instead of -.15. What do you need? Cheers, Rob -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]