note 102032 added to function.intval
| From: | TomEllis at osu1 dot php dot net | Date: | Mon, 24 Jan 2011 15:44:00 +0000 |
| Subject: | note 102032 added to function.intval | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-176246@lists.php.net to get a copy of this message | ||
Using intval on a floating point number loses the numbers after the decimal place.
So 19.99 would become 19.
You would need to use floatval instead see here: http://www.php.net/manual/en/function.floatval.php
@winbill, for your examples you would do
<?php
$n="19.99";
print floatval( $n * 100 ); // prints 1999
//Or
print floatval( strval( $n * 100 ) ); // prints 1999
//Or
print floatval( strval( $n ) * 100 ); // also prints 1999
?>
----
Server IP: 69.147.83.197
Probable Submitter: 81.137.61.197
----
Manual Page -- http://www.php.net/manual/en/function.intval.php
Edit -- https://master.php.net/note/edit/102032
Del: integrated -- https://master.php.net/note/delete/102032/integrated
Del: useless -- https://master.php.net/note/delete/102032/useless
Del: bad code -- https://master.php.net/note/delete/102032/bad+code
Del: spam -- https://master.php.net/note/delete/102032/spam
Del: non-english -- https://master.php.net/note/delete/102032/non-english
Del: in docs -- https://master.php.net/note/delete/102032/in+docs
Del: other reasons-- https://master.php.net/note/delete/102032
Reject -- https://master.php.net/note/reject/102032
Search -- https://master.php.net/manage/user-notes.php