Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: write off function using regex

by Krambambuli (Curate)
on May 24, 2010 at 08:24 UTC ( [id://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.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (4)
As of 2024-04-26 00:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found