On 15 Mar 2007 at 8:05, Tom Phoenix wrote: > 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? Right on the money! "%0.f" gives me: B5390493 0.59 1 B5390494 0.58 1 B5390495 0.54 1 B5390497 0.54 1 B5390498 0.53 1 B5700917 0.53 1 B5700918 0.54 1 Which is what I wanted. The sprintf documentation in the perlfunc manpage is quite extensive. There no problem with the docs, just my understanding of decimal and floating point numbers. Thanx again Tom, Dp. -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/