in reply to Re: Rounding Variables
in thread Rounding Variables

Just to keep things straight, to get "0.21" you'd need to use
$roundeddistance = sprintf "%4.2f", $distance;

as the number to the left of the decimal in the format must be the minimum number of characters in the output including the leading zero (if indeed it's a zero) and the decimal.

I should also add that rounding is not quite as simple as it first appears, depending on your field of work. For example, some need to always round 0.5 up, but others alternately round up and down in order to reduce the accumulated overestimate error in a sum of such rounded numbers. I've been tripped up by this a number of times...