Keep It Simple, Stupid | |
PerlMonks |
Proper creation of a negative numberby insta.gator (Novice) |
on Jul 08, 2015 at 13:23 UTC ( [id://1133717]=perlquestion: print w/replies, xml ) | Need Help?? |
insta.gator has asked for the wisdom of the Perl Monks concerning the following question: Hi Monks. I have a script that parses numeric values from a file. We have discovered that when a negative value exists in the file, it is displayed with the negative sign following the number rather than preceding the number. My script seems to be just ignoring the negative sign. Here is the code
So for example, the value of @line8 may be 7.89-. Later in the script we format the value as follows: $total = sprintf("%.2f", @TFCNTL_Tax[$i]); # Format number for floating point mathThe result is that the negative number becomes a positive number. I am assuming that we need to do some sort of test to determine if there is a minus sign following the number and then alter the variable to make it an actual negative number. Just not sure how to go about this. Can someone please help me with the best way to fix this? Thanks!
Back to
Seekers of Perl Wisdom
|
|