Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with calculation in script 1

Status
Not open for further replies.

WebWired

ISP
Mar 26, 2003
10
US
In this script I'm not sure how to make these calculations work right... can someone help please? The $biannually and $yearly vars.

<?php
switch ($package) {
case &quot;Special&quot;:
$price = &quot;9.95&quot;;
print&quot;<center>You have chosen the WebWired special.</center><br><br>&quot;;
break;
case &quot;PackageA&quot;:
$price = &quot;11.95&quot;;
print&quot;<center>You have chosen Package A.</center><br><br>&quot;;
break;
case &quot;PackageB&quot;:
$price = &quot;15.95&quot;;
print&quot;<center>You have chosen Package B.</center><br><br>&quot;;
break;
case &quot;ResellerA&quot;:
$price = &quot;29.95&quot;;
print&quot;<center>You have chosen Reseller Package A.</center><br><br>&quot;;
break;
case &quot;ResellerB&quot;:
$price = &quot;39.95&quot;;
print&quot;<center>You have chosen Reseller Package B.</center><br><br>&quot;;
break;
}
$monthly = &quot;$price&quot;;
$biannually = &quot;($price - 1) * 6&quot;;
$yearly = &quot;($price - 2) * 12&quot;;
?>
<?php
print&quot;
<input type=radio name=total value=$monthly>$$monthly /mo<br>
<input type=radio name=total value=$biannually>$$biannually /6 mo<br>
<input type=radio name=total value=$yearly>$$yearly /12 mo<br>
&quot;;
?>
 
You are using all strings. Just use the double values for the calculation:
....
case &quot;ResellerB&quot;:
$price = 39.95; // not &quot;39.95&quot;
print &quot;blah...&quot;
break;

# calculations should be numeric, not strings
$monthly = $price;
$biannually = ($price-1)*12;
$yearly = ($price-2)*12;
....
For output in a specific format use number_format();
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top