Forum Moderators: coopster

Message Too Old, No Replies

Function with maths.

php fuction for vat and markup.

         

ski442

7:36 pm on Jan 20, 2009 (gmt 0)

10+ Year Member



Hi Guys.
It must be fuction problem day, as I too have a small query.
This is my very first function i have written and I know it's wrong.

I have db with a number of fields all populated, what I would like to do is get the COST from the db add uk vat then add MARKUP.
This is what I have so far.

<?php
function markup() {

$cost = $Scost;
$vat = '15';
$markup = $Smarkup;

$total = $Scost * $vat * $Smarkup;

echo $total;
}
?>
&pound;<? echo markup($total) ?>

I hope this makes sense.

Vat is as you know 15% UK and the markup is just a number stored in the db which is 10 at the moment and should represent a percentage.

Thanks very much for yur time
Ski442

mark_roach

9:34 pm on Jan 20, 2009 (gmt 0)

10+ Year Member



If markup is a percentage then you need

$total = $Scost * (1+ $vat/100) * (1 + $Smarkup/100);

ski442

9:19 pm on Jan 21, 2009 (gmt 0)

10+ Year Member



Hi Mark,
Thanks for your reply. I could not get the whole code to work so I just had a play around and have come up with this.

<p> <? echo $total = $Scost * (1+$SITEvat/100) * (1+$SITEmarkup/100);
$total = round($total, 2) ?>

All the values are called from the db, but how is this working without being in a fuction.
Would this be considered OK or not
The code works perfectly, your expert veiws please.
Thanks Ski442