UPDATE - answer was in comments... looking at the code has a part where the variable was getting asigned not zero instead of checking if not zero. != vs =!
this is not the 3 = == === question, this bug was a bit more esoteric.
this is not about floating point math in general being broken... it IS NOT THE SAME ISSUE - this is likely an automatic type conversion - not float precision issue:
TL;DR: relevent code
$weightOfTenPieces = $_POST['weightOfTenPieces'];
$weightOfTenPieces = floatval($weightOfTenPieces);
$Weight = mysqli_real_escape_string($conn, $_POST['Weight']);
$CalWeight = floatval($Weight);
switch($ContainerType)
{
case "PALLETOFBOXES":
$containerWeight = 24 + (1 * $containerCount);
break;
$TARE = $_POST['TARE'];
$tare = floatval($TARE);
$tare = $tare + $containerWeight;
$materialweight = $CalWeight - $tare;
$PieceTen = $materialweight / $weightOfTenPieces;
echo "PieceTen calculated at: ".$PieceTen."<br />";
the above code results in a correct responce in phpfiddle. but when I run it on my server - it beheavies as if $weightOfTenPieces == 1 when $PieceTen gets assigned - regardless of actual value... if echo'ed before - it gives the correct value... the numbers for weightoftenpeices would be something like 0.32... when hard coded in the $PieceTen assignment it returns the expected value.
messing with floating point percision, type conversions, casting - all sorts of things... no luck.
$weightOfTenPieces = $_POST['weightOfTenPieces'];
$weightOfTenPieces = floatval($weightOfTenPieces);
$ContainerType = mysqli_real_escape_string($conn, $_POST['ContainerType']);
$Weight = mysqli_real_escape_string($conn, $_POST['Weight']);
$PieceNumber = 0;
$containerNumber = mysqli_real_escape_string($conn, $_POST['containerNumber']);
$containerCount = intval($containerNumber);
$CalWeight = floatval($Weight);
//weight calculated in oz to avoid floating point numbers
echo "container count::".$containerCount."<br /> CalWeight:: ".$CalWeight."<br /> weight of ten pieces:: ".$weightOfTenPieces."<br />";
switch($ContainerType)
{
case "PALLETOFBOXES":
$containerWeight = 24 + (1 * $containerCount);
break;
case "PALLET":
$containerWeight = 24 * $containerCount;
case "BOX":
$containerWeight = 1 * $containerCount;
break;
case "TUB":
$containerWeight = 2 * ($containerCount);
break;
default:
$containerWeight = 1 * $containerCount;
break;
}
echo "container weight:: ".$containerWeight."<br />";
if ($weightOfTenPieces =! 0 &&
$weightOfTenPieces =! null &&
$containerWeight != null &&
$containerWeight != 0 )
{
$TARE = $_POST['TARE'];
$tare = floatval($TARE);
$tare = $tare + $containerWeight;
//convert weight from lbs to oz
$materialweight = $CalWeight - $tare;
echo "material weight calculated at: ".$materialweight."<br />";
$PieceTen = $materialweight / $weightOfTenPieces;
echo "PieceTen calculated at: ".$PieceTen."<br />";
$PieceNumber = $PieceTen * 10;
}
else
{
ECHO "not calucalted route";
$PieceNumber = "not calculated";
}
echo "piece number calculated at: ".$PieceNumber."<br />";
debug result screen:
container count::5
CalWeight:: 337
weight of ten pieces:: 0.32
container weight:: 29
material weight calculated at: 308
PieceTen calculated at: 308
piece number calculated at: 3080
Record updated successfully
I expect 962.5 for pieceTen and 9,625 for PieceNumber
I expect 962.5 for pieceTen and 9,625 for PieceNumber