Gossamer Forum
Home : Products : DBMan : Customization :

Math Calculations - Need Help!

Quote Reply
Math Calculations - Need Help!
I have the following codes in sub add_record and sub modify_record before $status = &validate_record:

Code sample 1 to remove any $, commas or whitespace that the user may have entered:

Code:
$in{'Item1ListPriceEach'} =~ s/\$//g;
$in{'Item1ListPriceEach'} =~ s/,//g;
$in{'Item1ListPriceEach'} =~ s/ //g;
$in{'Item1TotalListPrice'} =~ s/\$//g;
$in{'Item1TotalListPrice'} =~ s/,//g;
$in{'Item1TotalListPrice'} =~ s/ //g;
$in{'Item1NetPriceEach'} =~ s/\$//g;
$in{'Item1NetPriceEach'} =~ s/,//g;
$in{'Item1NetPriceEach'} =~ s/ //g;
$in{'Item1TotalSellPrice'} =~ s/\$//g;
$in{'Item1TotalSellPrice'} =~ s/,//g;
$in{'Item1TotalSellPrice'} =~ s/ //g;

Code sample 2 to perform some math functions:

Code:
$in{'Item1TotalListPrice'} = $in{'Item1ListPriceEach'} * $in{'Item1Quantity'};
$in{'Item1NetPriceEach'} = $in{'Item1ListPriceEach'} * $in{'Item1Multiplier'} * $in{'Item1MarkUp'};
$in{'Item1TotalSellPrice'} = $in{'Item1NetPriceEach'} * $in{'Item1Quantity'};


Here is my problem. DbMan (or Perl in gerneral) does not remove the $, commas or whitespaces unitl after the sub routine executes. Therefore, when my math functions run, I get incorrect data.

For example, the user enters List Price of $1,000.00, Quantity of 1, Multiplier of .25 and Markup of 1.

The calculations run (before the routine has had a chance to remove the commas, $ or whitespaces) and instead of getting a value that should look correct, everything comes out to $1 or what ever was entered. The commas are messing me up. Is there any other way to perform the math part AFTER the validate routine removes the $, commas and whitespace? The codes I have above were taken from an example by JPDeni and placed where she recommended. Can anyone help????