Jump to content

Please help with php maths


lingo5

Recommended Posts

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.

Link to comment
https://forums.phpfreaks.com/topic/254966-please-help-with-php-maths/
Share on other sites

Archived

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

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