Jump to content

Archived

This topic is now archived and is closed to further replies.

magicmark

Real Numbers *.** instead of Integers?

Recommended Posts

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;

Share this post


Link to post
Share on other sites
You need to pass the scale parameter to set the number of digits after the decimal point on some of the functions.

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

Share this post


Link to post
Share on other sites

×

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.