Derold Posted May 21, 2013 Share Posted May 21, 2013 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 atderolds.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"; } ?> Quote Link to comment https://forums.phpfreaks.com/topic/278230-form-calculater/ Share on other sites More sharing options...
Eiseth Posted May 21, 2013 Share Posted May 21, 2013 Try BC Math functions http://www.php.net/manual/en/ref.bc.php Quote Link to comment https://forums.phpfreaks.com/topic/278230-form-calculater/#findComment-1431304 Share on other sites More sharing options...
Derold Posted May 21, 2013 Author Share Posted May 21, 2013 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"]); Quote Link to comment https://forums.phpfreaks.com/topic/278230-form-calculater/#findComment-1431403 Share on other sites More sharing options...
khyzer Posted June 18, 2013 Share Posted June 18, 2013 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"; } Quote Link to comment https://forums.phpfreaks.com/topic/278230-form-calculater/#findComment-1436552 Share on other sites More sharing options...
Derold Posted February 10, 2014 Author Share Posted February 10, 2014 OK I got this. Here is the new updated version at http://derolds.com/calc18.php . Take a look. Copy it. use it. change it. Quote Link to comment https://forums.phpfreaks.com/topic/278230-form-calculater/#findComment-1468357 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.