Jump to content


Photo

Real Numbers *.** instead of Integers?


  • Please log in to reply
1 reply to this topic

#1 magicmark

magicmark
  • New Members
  • Pip
  • Newbie
  • 1 posts

Posted 25 March 2006 - 04:59 PM

Please Please Please help me make this script display a real number as the result without using normal + & - PHP e.g. $Total + $Shipping?

//Variables

$Coupon = '22002';
$Total = 149;
$Shipping = 12.50;

//20% Discount Calculation

$Discount = bcmul($Total, '0.2');
$Discounted = bcsub($Total, $Discount);

//If Statement for Criteria, Compulsory Inputs or Handling

if (empty($Coupon)) {
$TotalWithShipping = bcadd($Total, $Shipping);

} elseif ( $Coupon == '22001' || $Coupon == '22002' ){

$TotalWithShipping = bcadd($Discounted, $Shipping);
} else {
echo "Invalid Coupon Code!";
}

//Display Result

echo $TotalWithShipping;

#2 annihilate

annihilate
  • Members
  • PipPipPip
  • Advanced Member
  • 63 posts
  • LocationUK

Posted 25 March 2006 - 05:07 PM

You need to pass the scale parameter to set the number of digits after the decimal point on some of the functions.

For example:
$Discount = bcmul($Total, '0.2', 2);
$Discounted = bcsub($Total, $Discount, 2);

Personal site: NewEnigma  |  Java and JSF Discussion




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users