Jump to content

[SOLVED] Calculating help cheers.


redarrow

Recommended Posts

Advance thank you.

 

I was creating a advance basket for a company and i am stuck.

 

not used the old maths function's for years can you help..

 

looks wrong.

<?php

$price="20.00";

$quienty="4";

$shipping="7.50";

$discount="20%";

$tax="17.50";

$payments="12";


$total=$price*$quienty;

$total=$total+$shipping;

$total=$total-$discount;


$taxrate=$tax/100;

$taxrate=$taxrate+1;

$total=$total*$taxrate;

$monthly=$total/$payments;

echo "Complete total ".£.number_format($total,2)."\n
<br> $payments monthly payments ".£.number_format($monthly,2)." ";

?>

 

result

 

Complete total £79.31 // how this correct no way?

 

12 monthly payments £6.61  // looks ok? from above result.

 

 

 

Link to comment
Share on other sites

Once thing I noticed

 

$total = $total - $discount

 

$discount is 20%. Can you subtract a real with a percent?

 

 

Also, that would total to about  87.5 without taxes. Whats so wrong about the numbers? Whats it supposed to be?

 

Also, everything looks fine to me besides the percent subtracting from a real.

 

EDIT: I just calculated myself and came to about 80 pounds. I don't think your code is wrong. Thats just the price. 17.5% is a hefty tax.

 

 

20 * 4 = (Price without anything)

 

80 * .8 ( .8 = 4/5 = 80% of orignal)

64 * 1.175 = 75.2 (Taxes)

75.2 + 7.50 = 81.2 (Shipping, shipping doesn't have sales tax)

 

Edit: Yeah I screwed up my statistics and modified them to be accurate.

 

80$ is price, then discount, then you add the taxes, then shipping price.

Link to comment
Share on other sites

London is hefty lol, not my fault, not prime minister pal, lol...

 

 

can you show me the same in a OOP code please i love learning that stuff....

 

whale i thort ill ask on here because i am no good at php and i got it correct first time no way?

 

Link to comment
Share on other sites

What is the number you are wanting it to be? Through how sales go, I think  it would be 81.2, but frankly you aren't saying the number you want so I don't know if I have what you are gunning for or not.

 

I don't know OOP so can't help you there.

Link to comment
Share on other sites

Here a function way, nice i think ?

 

<?php
function add_shopping($price,$quienty,$shipping,$discount,$tax,$payments){
$total=$price*$quienty;
$total=$total+$shipping;
$total=$total-$discount;
$taxrate=$tax/100;
$taxrate=$taxrate+1;
$total=$total*$taxrate;
$monthly=$total/$payments;
echo "Complete total ".£.number_format($total,2)."\n
<br> $payments monthly payments ".£.number_format($monthly,2)." ";
return;
}
echo add_shopping('20.00','10','7.50','10%','17.50','12');
?>

 

short version

<?php
function add_shopping($price,$quienty,$shipping,$discount,$tax,$payments){
$total=($price*$quienty)+($shipping)-($discount);
$taxrate=($tax/100)+($taxrate+1);
$total=$total*$taxrate;
$monthly=$total/$payments;
echo "Complete total ".£.number_format($total,2)."\n
<br> $payments monthly payments ".£.number_format($monthly,2)." ";
return;
}
echo add_shopping('20.00','1','7.50','10%','17.50','12');
?>

 

shortest i personally can go.

<?php
function add_shopping($price,$quienty,$shipping,$discount,$tax,$payments){
$total=($price*$quienty)+($shipping)-($discount);
$taxrate=($tax/100)+1;
$total=$total*$taxrate;
$monthly=$total/$payments;
echo "Complete total ".£.number_format($total,2)."\n
<br> $payments monthly payments ".£.number_format($monthly,2)." ";
return;
}
echo add_shopping('20.00','1','7.50','10%','17.50','12');
?>

Link to comment
Share on other sites

Last post on this sorry.

 

I added session's so the design of the web page, can be set up correctly.

 

 

<?php session_start();
function add_shopping($price,$quienty,$shipping,$discount,$tax,$payments){
$total=($price*$quienty)+($shipping)-($discount);
$taxrate=($tax/100)+1;
$total=$total*$taxrate;
$monthly=$total/$payments;
$_SESSION['monthly']=$monthly;
$_SESSION['total']=$total;
$_SESSION['payments']=$payments;
return;
}
echo add_shopping('20.00','1','7.50','10%','17.50','12');
echo "Complete total ".£.number_format($_SESSION['total'],2)."\n
<br> {$_SESSION['payments']} monthly payments ".£.number_format($_SESSION['monthly'],2)." ";
?>

 

If you learn all this maths stuff, as i have posted you can design a grate cart script.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

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.