[RESOLVED] Cal with php

Hello all,

I am wondering how can I do some math using PHP, I want to be able to take the following and do it with php

person comes along and enters 10.00 now I want to come up with the answer of:

var are being passed to a func called donation_cal()

10.00 * 2.9% + 0.30 =

the func passes either the donation plus the fee or it give just the donation amount then once the person clicks next this is passed to paypal, I just not sure how to handle math

I think its like

$total_donation = math($donation * $fee)+ $flat_fee

please help thanks
Christopher

$amount = ($donation * 1.029 + 0.3);

done :-)

Or for a function:

[php]// COME ON SPACING–.

function donate_cal($donation, $fee)
{
$fee = $fee / 100 + 1; // Convert to decimal, and add 1…

 return ($donation * $fee + 0.3);

}

// COME ON SPACING–.
[/php]

Ok, I got it to display now and every thing is good BUT one thing which is driving me nuts now as I have done the math and know what the correct answer is so here goes,

the code below gives a answer of when displayed:
Your total donation is:15.30249615

the code should be giving the answer of:
Your total donation is:15.549615

Whats going on here this is strage, if you take 1.29% / 100 it gives you 0.0129 which is what the computer I guess needs to be able to do the math

thank you for your help!

Sincerely,
Christopher

[php]

<?php function Donation_Cal($donation, $donate_fee = "yes") { $fee = 0.0129; $flat_fee = .30; if ( $donate_fee == "yes" ) { $total_donation = $donation * $fee * $fee + $flat_fee + $donation; } // 15.549615 = 15 * .0129 * .0129 + .3 + 15 else { $total_donation = $donation; } return $total_donation; }; echo "Your total donation is:" . Donation_Cal(15) ; ?>

[/php]

Order of operations:

Parenthesis
Exponents
multiplication
division
addition
subtraction

After using the order of operations, I come out with 15.302…

How do I mark this Resolved

Done :wink:

Sponsor our Newsletter | Privacy Policy | Terms of Service