Skip to content

Instantly share code, notes, and snippets.

@shaneog
Created June 5, 2012 16:31
Show Gist options
  • Save shaneog/2876091 to your computer and use it in GitHub Desktop.
Save shaneog/2876091 to your computer and use it in GitHub Desktop.
PHP Floating Point weirdness
<?php
$a = 35.55;
echo $a.PHP_EOL;
$b = 100;
echo $a * $b.PHP_EOL;
$c = $a * $b;
echo $c.PHP_EOL;
var_dump($c);
echo gettype($c).PHP_EOL;
echo (int)$c.PHP_EOL;
echo (int)ceil($c).PHP_EOL;
echo (int)round($c).PHP_EOL;
printf('%.20f', $c);
// See https://bugs.php.net/bug.php?id=47208
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment