note 117624 added to function.intval
| From: | taylorsarrafian at gmail dot com | Date: | Sat, 11 Jul 2015 04:45:43 +0000 |
| Subject: | note 117624 added to function.intval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-203074@lists.php.net to get a copy of this message | ||
beware:
<?php
// observe the following
echo intval( strval( -0.0001 ) ); // 0
echo intval( strval( -0.00001 ) ); // -1
// this is because
echo strval( -0.0001 ); // -.0001
echo strval( -0.00001 ); // -1.0E-5
// thus beware when using
function trunc2_bad( $n ) {
return intval( strval( $n * 100 ) / 100 );
}
// use this instead
function trunc2_good( $n ) {
return intval( floatval( strval( $n * 100 ) ) / 100 );
}
?>
----
Server IP: 72.52.91.14
Probable Submitter: 173.196.55.98
----
Manual Page -- http://php.net/manual/en/function.intval.php
Edit -- https://master.php.net/note/edit/117624
Del: integrated -- https://master.php.net/note/delete/117624/integrated
Del: useless -- https://master.php.net/note/delete/117624/useless
Del: bad code -- https://master.php.net/note/delete/117624/bad+code
Del: spam -- https://master.php.net/note/delete/117624/spam
Del: non-english -- https://master.php.net/note/delete/117624/non-english
Del: in docs -- https://master.php.net/note/delete/117624/in+docs
Del: other reasons-- https://master.php.net/note/delete/117624
Reject -- https://master.php.net/note/reject/117624
Search -- https://master.php.net/manage/user-notes.php