Hi All.
I have the following part of a script which works out the TAX/VAT fro order.
my $tax_per = getTax();
my ($total_amount_old,$total_amount_tax);
$total_amount_old = $grand_total;
if($tax_per ne "")
{
$total_amount_tax = $grand_total * (getTax()/100);
my $pt = index($total_amount_tax,".");
if($pt eq "-1")
{
$total_amount_tax = $total_amount_tax . ".00";
}
$total_amount = $grand_total + $total_amount_tax;
##print "total_amount_tax = " . $total_amount_tax;
}
######## end of including vat/tax to total amount #######
######## formatting total amount #######
my $pt = index($total_amount,".");
if($pt ne "-1")
{
my $before_decimal = substr($total_amount,0,$pt);
my $after_decimal = substr($total_amount,$pt+1);
$after_decimal = substr($after_decimal,0,2);
$total_amount = $before_decimal . "." . $after_decimal;
##print "before_decimal = " . $before_decimal . "<br>";
##print "after_decimal = " . $after_decimal . "<br>";
}
else
{
$total_amount = $total_amount . ".00";
}
######## end of formatting total amount #######
The problem im having is that the TAX / VAT ammount has too many digits after the decimal the other figures are ok. Heres an example?
Total Amount: GBP 24.99
Vat/Tax: GBP 4.37325
Grand Total: GBP 29.36
How can I correct this?
Thanks in advance!
I have the following part of a script which works out the TAX/VAT fro order.
Code:
######## including vat/tax to total amount ####### my $tax_per = getTax();
my ($total_amount_old,$total_amount_tax);
$total_amount_old = $grand_total;
if($tax_per ne "")
{
$total_amount_tax = $grand_total * (getTax()/100);
my $pt = index($total_amount_tax,".");
if($pt eq "-1")
{
$total_amount_tax = $total_amount_tax . ".00";
}
$total_amount = $grand_total + $total_amount_tax;
##print "total_amount_tax = " . $total_amount_tax;
}
######## end of including vat/tax to total amount #######
######## formatting total amount #######
my $pt = index($total_amount,".");
if($pt ne "-1")
{
my $before_decimal = substr($total_amount,0,$pt);
my $after_decimal = substr($total_amount,$pt+1);
$after_decimal = substr($after_decimal,0,2);
$total_amount = $before_decimal . "." . $after_decimal;
##print "before_decimal = " . $before_decimal . "<br>";
##print "after_decimal = " . $after_decimal . "<br>";
}
else
{
$total_amount = $total_amount . ".00";
}
######## end of formatting total amount #######
The problem im having is that the TAX / VAT ammount has too many digits after the decimal the other figures are ok. Heres an example?
Total Amount: GBP 24.99
Vat/Tax: GBP 4.37325
Grand Total: GBP 29.36
How can I correct this?
Thanks in advance!