imimin Posted June 26, 2009 Share Posted June 26, 2009 Could someone please help me? I need to write a math function that will take a value from a data base and calculate 75% of that value and echo it on my website. How can I do that? Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/163798-calculate-new-value-and-echo/ Share on other sites More sharing options...
Maq Posted June 26, 2009 Share Posted June 26, 2009 function seventyFive($bag) { echo $bag * .75; } Quote Link to comment https://forums.phpfreaks.com/topic/163798-calculate-new-value-and-echo/#findComment-864253 Share on other sites More sharing options...
imimin Posted June 26, 2009 Author Share Posted June 26, 2009 Should this work the same way if I set it up like this (see approximately line 12): <?php $item_selected_style = $_GET['item_selected_style']; $item_prod_name = $_GET['item_prod_name']; $item_retail = $_GET['item_retail']; $item_weight = $_GET['item_weight']; $item_img = $_GET['item_img']; echo " <INPUT TYPE=HIDDEN NAME=name VALUE='$item_prod_name'> <INPUT TYPE=HIDDEN NAME=price VALUE='$item_retail*.75'> <INPUT TYPE=HIDDEN NAME=sh VALUE='$item_weight'> <INPUT TYPE=HIDDEN NAME=img VALUE='https://secure.impact-impressions.com/poj/includes/img_resize3.php?src=$sitelocation$item_img&width=100&height=100&qua=50'> <INPUT TYPE=HIDDEN NAME=img2 VALUE=''> <INPUT TYPE=HIDDEN NAME=return VALUE='http://www.patternsofjoy.com'> <INPUT TYPE='RADIO' NAME='custom20' VALUE='Style: $item_selected_style' CHECKED='CHECKED' style='display:none'> <B>Garment Style: </B>$item_selected_style <BR>" ?> I tried this and it did not pass the value? Quote Link to comment https://forums.phpfreaks.com/topic/163798-calculate-new-value-and-echo/#findComment-864313 Share on other sites More sharing options...
WolfRage Posted June 26, 2009 Share Posted June 26, 2009 Try it like this: <?php echo "<INPUT TYPE=HIDDEN NAME=name VALUE='$item_prod_name'> <INPUT TYPE=HIDDEN NAME=price VALUE='"; echo $item_retail*.75; echo "'> <INPUT TYPE=HIDDEN NAME=sh VALUE='$item_weight'> <INPUT TYPE=HIDDEN NAME=img VALUE='https://secure.impact-impressions.com/poj/includes/img_resize3.php?src=$sitelocation$item_img&width=100&height=100&qua=50'> <INPUT TYPE=HIDDEN NAME=img2 VALUE=''> <INPUT TYPE=HIDDEN NAME=return VALUE='http://www.patternsofjoy.com'> <INPUT TYPE='RADIO' NAME='custom20' VALUE='Style: $item_selected_style' CHECKED='CHECKED' style='display:none'> <B>Garment Style: </B>$item_selected_style <BR>" ?> Yes I broke it up more than is probably necessary. Quote Link to comment https://forums.phpfreaks.com/topic/163798-calculate-new-value-and-echo/#findComment-864316 Share on other sites More sharing options...
imimin Posted June 26, 2009 Author Share Posted June 26, 2009 That didn't seem to work? ??? Any more ideas? Quote Link to comment https://forums.phpfreaks.com/topic/163798-calculate-new-value-and-echo/#findComment-864336 Share on other sites More sharing options...
natepizzle Posted June 26, 2009 Share Posted June 26, 2009 Try $item_retail = ($_GET['item_retail'] * .75); and remove *.75 from <INPUT TYPE=HIDDEN NAME=price VALUE='$item_retail*.75'> Quote Link to comment https://forums.phpfreaks.com/topic/163798-calculate-new-value-and-echo/#findComment-864348 Share on other sites More sharing options...
Lumio Posted June 26, 2009 Share Posted June 26, 2009 Maybe this will work: <?php if (array_key_exists('item_retail', $_GET)) echo floatval($_GET['item_retail']) * .75 Quote Link to comment https://forums.phpfreaks.com/topic/163798-calculate-new-value-and-echo/#findComment-864358 Share on other sites More sharing options...
imimin Posted July 5, 2009 Author Share Posted July 5, 2009 function seventyFive($bag) { echo $bag * .75; } How do you round this to 2 digits? Quote Link to comment https://forums.phpfreaks.com/topic/163798-calculate-new-value-and-echo/#findComment-869327 Share on other sites More sharing options...
imimin Posted July 5, 2009 Author Share Posted July 5, 2009 Sorry...I meant to say how do you round this off to 2 decimal places? Quote Link to comment https://forums.phpfreaks.com/topic/163798-calculate-new-value-and-echo/#findComment-869335 Share on other sites More sharing options...
Maq Posted July 6, 2009 Share Posted July 6, 2009 number_format Quote Link to comment https://forums.phpfreaks.com/topic/163798-calculate-new-value-and-echo/#findComment-869675 Share on other sites More sharing options...
pacchiee Posted July 6, 2009 Share Posted July 6, 2009 Function to round the result to two decimal points: <?php function seventyFive($bag) { echo round($bag * .75,2); } ?> You can call the function like below: <?php seventyFive(2500.98); ?> Output will be 1875.74 Quote Link to comment https://forums.phpfreaks.com/topic/163798-calculate-new-value-and-echo/#findComment-869715 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.