On 3/15/07, Beginner <[EMAIL PROTECTED]> wrote:

For some reason my sprintf usage is not returning the numbers I had
expected and appears to be rounding down. Is there something wrong
with my formatting below.

                my $ksize = sprintf("%.2f",$size/1024);
                my $mbsize = sprintf("%.2f",$ksize/1024);
                my $msize = sprintf("%d",$mbsize);

The %d format is for integers, so it always truncates any fractional
part. The %f is floating, so it rounds. If you want to round to the
nearest integer, then, use a format like "%.0f" or "%6.0f".

Does that solve your problem? The sprintf documentation in the
perlfunc manpage is quite extensive.

Cheers!

--Tom Phoenix
Stonehenge Perl Training

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to