pkassies has asked for the wisdom of the Perl Monks concerning the following question:
Hello everybody, I need to strip "90.00" back to "90". I wrote the following program #!/perl $item = "90.0"; print &strip_dot($item); sub strip_dot { print "1 - $_[0]\n"; if ($_[0] =~ m/./) { print "2 - $_[0]\n"; return substr ($_[0], 0, index($_[0],".")); } else { print "3 - $_[0]\n"; return "$_[0]"; } } its output is: 1 - 90.0 2 - 90.0 90 Great that works. but if I make $item = "90"; the output is: 1 - 90 2 - 90 9 Hmm, that is not what I want. The if statement should generate FALSE and it shouldn't be stripped to + 9. Any help is appreaciated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: stripping "." from amounts
by FunkyMonk (Bishop) on Jul 20, 2007 at 21:12 UTC | |
|
Re: stripping "." from amounts
by CountZero (Bishop) on Jul 20, 2007 at 22:15 UTC | |
by yaneurabeya (Novice) on Jul 20, 2007 at 22:47 UTC | |
by CountZero (Bishop) on Jul 21, 2007 at 06:46 UTC | |
|
Re: stripping "." from amounts
by graff (Chancellor) on Jul 21, 2007 at 04:58 UTC | |
|
Re: stripping "." from amounts
by swampyankee (Parson) on Jul 21, 2007 at 14:15 UTC | |
|
Re: stripping "." from amounts
by oxone (Friar) on Jul 21, 2007 at 14:10 UTC |