in reply to How do I print/round a number to a given number of decimal places?
strange that no-one has posted this, seems like the most straightforward idea to me...sub round { my ($nr,$decimals) = @_; return (-1)*(int(abs($nr)*(10**$decimals) +.5 ) / (10**$decimals)) + if $nr<0; return int( $nr*(10**$decimals) +.5 ) / (10**$decimals); }
|
|---|