Skip to content

Instantly share code, notes, and snippets.

@iamsujun
Last active August 29, 2015 14:16
Show Gist options
  • Save iamsujun/81228b9bc6707cd98620 to your computer and use it in GitHub Desktop.
Save iamsujun/81228b9bc6707cd98620 to your computer and use it in GitHub Desktop.
PHP浮点型乘积取整
<?php
echo (0.58*100) . "<br>"; //58
echo (int)(0.58*100) . "<br>"; //57
echo (1234.11 * 100) . "<br>"; //123411
echo (int)(1234.11 * 100) . "<br>"; //123410
echo intval(1234.12 * 100) . "<br>"; //123411
echo floor(( 0.1 + 0.7 ) * 10) . "\n"; //返回 7 而不是8,
echo (int)(( 0.1 + 0.7 ) * 10) . "\n"; //返回7而不是8.
echo (int)round( 0.1 + 0.7 ) * 10); //8
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment