Created
October 22, 2012 13:22
-
-
Save desigens/3931483 to your computer and use it in GitHub Desktop.
Hack for match with PHP's round()
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 | |
$rate = (float) 32.0115; | |
echo '<script>rate = ' . $rate . ';</script>'; | |
?> | |
<script> | |
function check(i, result) | |
{ | |
var r = rate + 0.000000000001; // Hack for match with PHP's round() | |
var jsresult = i * r; | |
var fresult = jsresult.toFixed(2); | |
if(fresult != result) | |
{ | |
// console.log(result,jsresult,fresult); | |
alert(result,jsresult,fresult); | |
} | |
} | |
</script> | |
<?php | |
for ($i = 0; $i < 10000; $i++) | |
{ | |
$result = round($i * $rate, 2); | |
echo $i . ' = ' . $result . '<br>'; | |
echo '<script>check('.$i.', '.$result.');</script>'; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment