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
@line = split (/\s+/, $line); # Split line on any amount of + whitespace $TFCNTL_Tax = @line[8]; $TFCNTL_Tax =~ s/(\$|,)//g; # Get rid of $ and comma +s push(@TFCNTL_Tax,$TFCNTL_Tax); # Save value for later print "TFCNTL_Tax=@TFCNTL_Tax\n\n";
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!
In reply to Proper creation of a negative number by insta.gator
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |