Jump to content

Form calculater


Derold

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";
}
?>
Link to comment
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"]);
Link to comment
Share on other sites

  • 4 weeks later...

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";
}
Link to comment
Share on other sites

  • 7 months later...
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.