R
Robert TV
Hi,
A portion of my script uses 'sprintf' to round some of my taxed currency
vaiables to 2 decimal places. I am having a problem when the rounding does
not produce 2 full decimal places. My formula EG:
$price = 12.99; #product price of $12.99
$taxrate = 7.0; #tax rate of 7%
$taxtotal = $price / 100; #divides price by 100
$taxtotal = $taxtotal * $taxrate; #multiply divided price times tax rate
$taxtotal = sprintf("%.02f",$taxtotal); #round the tax total - 2 decimal
places
$finalprice = $price + $taxtotal; #add the tax total to the original
price
print "$finalprice";
This method produces: 13.9
I would like it to produce: 13.90
Most of the prices this script crunches produces 2 decimal place final
totals, it's only when the tax total round evenly to 10/100'ths. How can I
modify this script to add a "0" (zero) to the end of any total that does not
have 2 decimal places? Also, if the above method for calculating the taxed
total is inefficient, I welcome alternative suggestions. TIA!
Robert
A portion of my script uses 'sprintf' to round some of my taxed currency
vaiables to 2 decimal places. I am having a problem when the rounding does
not produce 2 full decimal places. My formula EG:
$price = 12.99; #product price of $12.99
$taxrate = 7.0; #tax rate of 7%
$taxtotal = $price / 100; #divides price by 100
$taxtotal = $taxtotal * $taxrate; #multiply divided price times tax rate
$taxtotal = sprintf("%.02f",$taxtotal); #round the tax total - 2 decimal
places
$finalprice = $price + $taxtotal; #add the tax total to the original
price
print "$finalprice";
This method produces: 13.9
I would like it to produce: 13.90
Most of the prices this script crunches produces 2 decimal place final
totals, it's only when the tax total round evenly to 10/100'ths. How can I
modify this script to add a "0" (zero) to the end of any total that does not
have 2 decimal places? Also, if the above method for calculating the taxed
total is inefficient, I welcome alternative suggestions. TIA!
Robert