note 69774 added to function.gmp-init

From: Date: Wed, 20 Sep 2006 10:30:50 +0000
Subject: note 69774 added to function.gmp-init
Groups: php.notes 
Request: Send a blank email to php-notes+get-117346@lists.php.net to get a copy of this message
Here's a way to parse a decimal (eg 3.25) into an integer and exponent: <? if (preg_match("/^[0-9]+\.[0-9]+$/",$input)){ //Input is a base-10 decimal. Multiply as necessary to remove the decimal //point. Convert that to a gmp_resource, then decrement the exponent //to compensate. $pieces=explode(".", $input); //Split at the d.p. $input="$pieces[0]$pieces[1]"; //Remove the decimal point. $input=ltrim($input,'0'); //Remove any leading zeros, or gmp_init will parse the number as octal. if ($input==''){ //Deal with "0.0" which would otherwise be ''. $input=0; } $integer=gmp_init($input); $ns_exponent=-strlen($pieces[1]); //exponent = (-) the number of characters after the decimal point. } ?> ---- Server IP: 85.116.0.130 Probable Submitter: 81.187.87.42 ---- Manual Page -- http://www.php.net/manual/en/function.gmp-init.php Edit -- https://master.php.net/note/edit/69774 Del: integrated -- https://master.php.net/note/delete/69774/integrated Del: useless -- https://master.php.net/note/delete/69774/useless Del: bad code -- https://master.php.net/note/delete/69774/bad+code Del: spam -- https://master.php.net/note/delete/69774/spam Del: non-english -- https://master.php.net/note/delete/69774/non-english Del: in docs -- https://master.php.net/note/delete/69774/in+docs Del: other reasons-- https://master.php.net/note/delete/69774 Reject -- https://master.php.net/note/reject/69774 Search -- https://master.php.net/manage/user-notes.php

« previous php.notes (#117346) next »