Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re: write off function using regex

by Krambambuli (Deacon)
on May 24, 2010 at 08:24 UTC ( #841339=note: print w/ replies, xml ) Need Help??


in reply to write off function using regex

Maybe something like

#!/usr/bin/perl use strict; use warnings; use POSIX; my @data = qw( 9.90 9.91 9.9111 9.94999 9.95 9.950001 9.96 9.99 9.9999 +9); foreach my $x (@data) { printf "%s => %.2f\n", $x, floor( 20*$x) /20, "\n"; }
which outputs

9.90 => 9.90
9.91 => 9.90
9.9111 => 9.90
9.94999 => 9.90
9.95 => 9.95
9.950001 => 9.95
9.96 => 9.95
9.99 => 9.95
9.99999 => 9.95

would fit too ?

Your wanted writeoff function is then simply floor( 20 * x) /20.


Comment on Re: write off function using regex
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://841339]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (12)
As of 2014-10-23 10:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    For retirement, I am banking on:










    Results (125 votes), past polls