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

Zohar Kelrich lumi at musicgenome.com
Thu May 6 05:33:46 PDT 2004


On Thu, 06 May 2004 15:07:02 +0300
Yuval Yaari <yuval at windax.com> wrote:

> Hi,
> 
> I need to round numbers to their nearest quarter, e.g:
> 5.20 => 5.25
> 10.00 => 10.00 (no need to round)
> 10.40 => 10.50
> 3.70 => 3.75
> 3.80 => 3.75
> 
> All solutions (hacks and "kosher") are welcome...

This seems to do the trick:

my $f=$num*4;
print(($f<int $f+.5?int $f+1:int $f)/4)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: not available
Url : http://perl.org.il/pipermail/perl/attachments/20040506/48e80f24/attachment.pgp 


More information about the Perl mailing list