View Single Post
Old 07-11-2004, 02:35 PM   #1 (permalink)
sarah31
Code Monkey
 
sarah31's Avatar
 
Join Date: May 2002
Location: canada
Posts: 55
sarah31 is on a distinguished road
perplexing issue with some calculations

i have this code:

Code:
	$_POST['quantity'] = 0;
	for ($i=0;$i<30;$i++){
		$_POST['quantity'] += $_POST['q'.$i];
	}
	print "<div class='center-text'><b>Number of Books:</b> {$_POST['quantity']}</div>";

	$_POST['fmvtotal'] = 0;
	for ($i=0;$i<30;$i++){
		$_POST['fmvtotal'] += $_POST['fmv'.$i];
	}
	$_POST['fmvtotal'] = number_format ($_POST['fmvtotal'], 2);
	print "<div class='center-text'><b>FMV Total $:</b> {$_POST['fmvtotal']}</div>"; 

	if ($_POST['fmvtotal'] >= 1 && $_POST['fmvtotal'] <= 100) {
	$_POST['ins'] = '3.50';
	} elseif ($_POST['fmvtotal'] > 100) {
	$_POST['ins'] = (ceil(($_POST['fmvtotal'] - 100) / 100) * 0.45) + 3.50;
	} else {
	$_POST['ins'] = 0;
	}
	
	$_POST['ins'] = number_format ($_POST['ins'], 2);
	print "<div class='center-text'><b>Insurance Total $:</b> {$_POST['ins']}</div>"; 
	
	

	$_POST['servicesubtotal'] = $_POST['service']*$_POST['quantity'];
	
	$_POST['servicesubtotal'] = number_format ($_POST['servicesubtotal'], 2);
	print "<div class='center-text'><b>Service Charges $:</b> {$_POST['servicesubtotal']}</div>";

	if ($_POST['quantity'] == 1) {
	$_POST['shipping'] = '7.40';
	} elseif ($_POST['quantity'] == 2){
	$_POST['shipping'] = '10.90';
	} elseif ($_POST['quantity'] >= 3 && $_POST['quantity'] <= 5){
	$_POST['shipping'] = '14.90';
	} elseif ($_POST['quantity'] > 5) {
	$_POST['shipping'] = (($_POST['quantity']-5)*1)+14.90;
	} else {
	$_POST['shipping'] = 0;
	}

	$_POST['shipping'] = number_format ($_POST['shipping'], 2);
	print "<div class='center-text'><b>Shipping Cost:</b> {$_POST['shipping']}</div><br>";

	//grand total calculation

	$_POST['grandtotal'] = $_POST['shipping']+$_POST['servicesubtotal']+$_POST['ins'];
	$_POST['grandtotal'] = number_format ($_POST['grandtotal'], 2);
	print "<div class='center-text'><b>GRAND TOTAL$:</b> {$_POST['grandtotal']}</div>";

now if i have the following numbers entered:

Code:
Quantity 90
Publisher DC
Title Wonder Woman
Issue # 105
Month/Year June 1958
FMV 11250
i get this output:
Code:
Number of Books: 90
FMV Total $: 11,250.00
Insurance Total $: 3.50
Service Charges $: 1,260.00
Shipping Cost: 99.90

GRAND TOTAL$: 104.40
obviously the insurance (ins) calculation is not accepting the FMV Total number into the calculation and the shipping total is not being allowed into the grand total either. i have looked and look for an answer but i haven't found any explanation and i need this fixed.
sarah31 is offline   Reply With Quote