Jump to content

Archived

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

Derold

Form calculater

Recommended Posts

Help!!!!!! i am making a form that calculates this is the line that i am having problems with.
It works but when i add *.01+ the calculation is wrong. you can see the test page at
derolds.com/calc15.php
<?php
if (count($_POST) > 0 && isset($_POST["calc15TextArea2"])){
        $sum = floatval( $_POST["indexEditbox1"] ) + floatval( $_POST["indexEditbox2"] ) 
*.01+ floatval( $_POST["calc15Editbox3"] ) + floatval( $_POST["calc15Editbox4"] ) ;
     echo "Total is $ $sum";
}
?>

Share this post


Link to post
Share on other sites

Ok i got it now. I changed the line to this. Needed to get total of the first two first then add the second two. 

$sum = (floatval($_POST["indexEditbox1"]) + floatval($_POST["indexEditbox2"])) * 1.01+ floatval($_POST["calc15Editbox3"]) + floatval($_POST["calc15Editbox4"]);

Share this post


Link to post
Share on other sites

use brackets 

1.if u wants add first two numbers then multiply with 0.01 use this

 
if (count($_POST) > 0 && isset($_POST["calc15TextArea2"])){
        $sum = ((floatval( $_POST["indexEditbox1"] ) + floatval( $_POST["indexEditbox2"] )) 
*.01 )+ floatval( $_POST["calc15Editbox3"] ) + floatval( $_POST["calc15Editbox4"] ) ;
     echo "Total is $ $sum";
}
 
 
2 if u want multiply only second number with 0.01 then use this
 
if (count($_POST) > 0 && isset($_POST["calc15TextArea2"])){
        $sum = floatval( $_POST["indexEditbox1"] ) + (floatval( $_POST["indexEditbox2"])  
*.01 )+ floatval( $_POST["calc15Editbox3"] ) + floatval( $_POST["calc15Editbox4"] ) ;
     echo "Total is $ $sum";
}

Share this post


Link to post
Share on other sites

×
×
  • 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.