Skip to content

Instantly share code, notes, and snippets.

@caramelchocolate
Created April 9, 2020 14:45
Show Gist options
  • Save caramelchocolate/58a8360795db48027bef411825c34a40 to your computer and use it in GitHub Desktop.
Save caramelchocolate/58a8360795db48027bef411825c34a40 to your computer and use it in GitHub Desktop.
Round-off error example
<?php
$a = 0.1 + 0.1 + 0.1;
$b = 0.3;
if ($a != $b) {
echo "Round-off error" . PHP_EOL;
}
$a = (0.1 * 0.1) * 30;
$b = 0.3;
if ($a != $b) {
echo "Round-off error" . PHP_EOL;
}
$a = (0.1 * 0.1) / 0.1;
$b = 0.1;
if ($a != $b) {
echo "Round-off error" . PHP_EOL;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment