[Israel.pm] Rounding numbers to the nearest quarter???

Yuval Kogman lists at woobling.org
Thu May 6 06:34:24 PDT 2004


On Thu, May 06, 2004 at 15:11:15 +0300, Jason Elbaum wrote:
> Multiply by four, round to nearest integer, divide by four:
> 
> x=2.70
> x*4 = 10.80
> round(x*4) = 11
> round(x*4)/4 = 2.75

I actually believed this was the idiom for rounds of all sorts, and
would do stuff like int(($x * 100) + 0.5)/100 to acheive a percision of
two decimal points... Self tought programming sucks - you only find out
of essentials much later on.

-- 
 ()  Yuval Kogman <nothingmuch at woobling.org> 0xEBD27418  perl hacker &
 /\  kung foo master: /methinks long and hard, and runs away: neeyah!!!

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 186 bytes
Desc: not available
Url : http://perl.org.il/pipermail/perl/attachments/20040506/86820170/attachment.pgp 


More information about the Perl mailing list