note 102032 deleted from function.intval by danbrown

From: Date: Mon, 24 Jan 2011 15:54:06 +0000
Subject: note 102032 deleted from function.intval by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-176248@lists.php.net to get a copy of this message
Note Submitter: Tom Ellis ---- 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 ?>

« previous php.notes (#176248) next »