Welcome to the Monastery | |
PerlMonks |
write off function using regexby suhailck (Friar) |
on May 24, 2010 at 06:43 UTC ( [id://841328]=perlquestion: print w/replies, xml ) | Need Help?? |
suhailck has asked for the wisdom of the Perl Monks concerning the following question:
Hi Monks, I'm trying to write a writeoff function using regex It should work as follows, writeoff(9.91) => 9.90 writeoff(9.92) => 9.90 . writeoff(9.94) => 9.90 writeoff(9.95) => 9.95 . . writeoff(9.99) => 9.95 Below is the code i tried perl -le '($_=shift)=~s/(\.[0-9])([0-9])/$1(?($2>=5)5|0)/;print' 9.97 OUTPUT 9.9(?(7>=5)5|0) Please let me know where im doing wrong and other regex implementation of the same Thanks in advance!!
Back to
Seekers of Perl Wisdom
|
|