lingo5 Posted January 13, 2012 Share Posted January 13, 2012 Hi, I am using PHP to perform some area calculations. I have created this form to collect the values: <form name="form1" method="post" action="<?php htmlentities($_SERVER['PHP_SELF']); ?>"> <table width="100%" border="0" cellspacing="0" cellpadding="8"> <tr> <td><table width="100%" border="0" cellspacing="0" cellpadding="1"> <tr> <td bgcolor="#666666"><table width="100%" border="0" cellspacing="0" cellpadding="4"> <tr> <td align="center" bgcolor="#3471C6" class="fondoHogartec"><?=CNT_TXT_CALCULATORTITLE?></td> </tr> <tr> <td align="center" bgcolor="#EEEEDD"><label> <span class="CarritoProducto"><?=CNT_TXT_WATERLINE?><br> </span> <input name="waterline" type="text" class="CalculatorFieldTXT" id="waterline" value="<?php echo((isset($_POST["waterline"]))?$_POST["waterline"]:"") ?>"> </label></td> </tr> <tr> <td align="center" bgcolor="#EEEEDD"><label> <span class="CarritoProducto"><?=CNT_TXT_BEAM?></span><br> <input name="beam" type="text" class="CalculatorFieldTXT" id="beam" value="<?php echo((isset($_POST["beam"]))?$_POST["beam"]:"") ?>"> </label></td> </tr> <tr> <td align="center" bgcolor="#EEEEDD"><label> <span class="CarritoProducto"><?=CNT_TXT_DRAUGHT?></span><br> <input name="draught" type="text" class="CalculatorFieldTXT" id="draught" value="<?php echo((isset($_POST["draught"]))?$_POST["draught"]:"") ?>"> </label></td> </tr> <tr> <td align="center" bgcolor="#EEEEDD"><label> <span class="CarritoPrecio"><?=CNT_TXT_SURFACE?><br> </span> <input name="surface" type="text" class="CalculatorFieldTXT" id="surface" value="<?php echo $total_surface ?>" size="10" > </label></td> </tr> <tr> <td align="center" nowrap bgcolor="#EEEEDD"><label class="CarritoPrecio"><?=CNT_TXT_TOTALCANS?><br> </label> <input name="cans_needed_2coats" type="text" class="CalculatorFieldTXT" id="cans_needed_2coats" value="<?php echo $total_cans ?>"> <br></td> </tr> <tr> <td align="center" nowrap bgcolor="#EEEEDD"><table width="100%" border="0" cellspacing="0" cellpadding="2"> <tr> <td colspan="3" align="center" class="TitulosTXT2"><?=CNT_TXT_KEELTYPE?></td> </tr> <tr> <td align="center" class="TitulosTXT2"><label> <input type="submit" name="keel_type" id="keel_type" value="<?=CNT_TXT_LONG?>"> </label></td> <td align="center"><input type="submit" name="keel_type" id="keel_type" value="<?=CNT_TXT_BILGE?>"></td> <td align="center"><input type="submit" name="keel_type" id="keel_type" value="<?=CNT_TXT_FIN?>"></td> </form> and this is the PHP to perform the calculations: // INICIATE CALCULATOR $keeltype = $_POST["keel_type"]; $waterline_length = $_POST["waterline"]; $beam = $_POST["beam"]; $draught = $_POST["draught"]; if ($keeltype == CNT_TXT_LONG) { $total_surface = $waterline_length*($beam+$draught) ; } if ($keeltype == CNT_TXT_BILGE) { $total_surface = ($waterline_length*($beam+$draught))* 0.75 ; } if ($keeltype == CNT_TXT_FIN) { $total_surface = ($waterline_length*($beam+$draught))* 0.50 ; } $total_cans = $total_surface / 25 ; // END CALCULATOR It works fine when the values entered in the form contain decimals separated by "." but it doesn't calculate properly when the decimals are separated by a comma. Please help. Thanks. Quote Link to comment https://forums.phpfreaks.com/topic/254966-please-help-with-php-maths/ Share on other sites More sharing options...
The Little Guy Posted January 13, 2012 Share Posted January 13, 2012 replace the commas with nothing. Example: $waterline_length = str_replace(",","",$waterline_length); Quote Link to comment https://forums.phpfreaks.com/topic/254966-please-help-with-php-maths/#findComment-1307312 Share on other sites More sharing options...
lingo5 Posted January 13, 2012 Author Share Posted January 13, 2012 Many thanks Little Guy...that worked perfect. Quote Link to comment https://forums.phpfreaks.com/topic/254966-please-help-with-php-maths/#findComment-1307321 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.