Created
March 1, 2018 21:25
-
-
Save bagart/13067cdda2730dbd26e59fffdf5a8c21 to your computer and use it in GitHub Desktop.
work with float
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// https://3v4l.org/0Fonp | |
$x = 1.999999999999999; | |
$y = 2; | |
var_dump([ | |
'float: 1.999999999999999' => [ | |
'serilize' => [$x, 'orig' => serialize($x), 'int' => serialize((int)$x), 'round' => serialize(round($x)), $x < 2], | |
'int' => [(int)$x, (int)$x < 2], | |
'string'=>[(string)$x, (string)$x < 2], | |
'round' => [round($x), round($x) < 2], | |
], | |
'int: 2' => [ | |
'serilize' => [$y, 'orig' => serialize($y), 'int' => serialize((int)$y), 'round' => serialize(round($y)), $y < 2], | |
'int' => [(int)$y, (int)$y < 2], | |
'string'=>[(string)$y, (string)$y < 2], | |
'round' => [round($y), round($y) < 2], | |
], | |
]); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Older php version - other result: