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.

Revisions

  1. iamsujun revised this gist Mar 12, 2015. 1 changed file with 6 additions and 6 deletions.
    12 changes: 6 additions & 6 deletions float.php
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,11 @@
    <?php
    echo (0.58*100) . "<br>";
    echo (int)(0.58*100) . "<br>";
    echo (1234.11 * 100) . "<br>";
    echo (int)(1234.11 * 100) . "<br>";
    echo intval(1234.12 * 100) . "<br>";
    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);
    echo (int)round( 0.1 + 0.7 ) * 10); //8
  2. iamsujun revised this gist Mar 12, 2015. 1 changed file with 6 additions and 1 deletion.
    7 changes: 6 additions & 1 deletion float.php
    Original file line number Diff line number Diff line change
    @@ -3,4 +3,9 @@
    echo (int)(0.58*100) . "<br>";
    echo (1234.11 * 100) . "<br>";
    echo (int)(1234.11 * 100) . "<br>";
    echo intval(1234.12 * 100) . "<br>";
    echo intval(1234.12 * 100) . "<br>";

    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);
  3. iamsujun renamed this gist Mar 12, 2015. 1 changed file with 0 additions and 0 deletions.
    File renamed without changes.
  4. iamsujun created this gist Mar 12, 2015.
    6 changes: 6 additions & 0 deletions gistfile1.php
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,6 @@
    <?php
    echo (0.58*100) . "<br>";
    echo (int)(0.58*100) . "<br>";
    echo (1234.11 * 100) . "<br>";
    echo (int)(1234.11 * 100) . "<br>";
    echo intval(1234.12 * 100) . "<br>";