note 98001 added to function.bcscale
| From: | codeslinger at compsalot dot com | Date: | Thu, 20 May 2010 02:42:41 +0000 |
| Subject: | note 98001 added to function.bcscale | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-169439@lists.php.net to get a copy of this message | ||
the function in the note below seems a bit more complicated then it really needs to be. since we
are dealing with strings, we can use the string functions instead.
<?php
function DecimalClean($Input)
{
return (strpos($Input, '.') === false) ? $Input : rtrim($Input, '0');
}
?>
Explanation:
First we check to see if the number contains a decimal point (we assume that it is a sane/valid
number).
If the number lacks a decimal point then we do not need to do anything, otherwise we use the trim
function which is very fast because it is a low level function, to remove the zeros. Trim will stop
at the first character that is not a '0'.
The only limitation is that this version does not account for localized decimal points.
----
Server IP: 69.147.83.197
Probable Submitter: 174.21.219.64
----
Manual Page -- http://www.php.net/manual/en/function.bcscale.php
Edit -- https://master.php.net/note/edit/98001
Del: integrated -- https://master.php.net/note/delete/98001/integrated
Del: useless -- https://master.php.net/note/delete/98001/useless
Del: bad code -- https://master.php.net/note/delete/98001/bad+code
Del: spam -- https://master.php.net/note/delete/98001/spam
Del: non-english -- https://master.php.net/note/delete/98001/non-english
Del: in docs -- https://master.php.net/note/delete/98001/in+docs
Del: other reasons-- https://master.php.net/note/delete/98001
Reject -- https://master.php.net/note/reject/98001
Search -- https://master.php.net/manage/user-notes.php