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"; } ?> 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 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"]); 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"; } 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. Link to comment https://forums.phpfreaks.com/topic/278230-form-calculater/#findComment-1468357 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.