note 98001 deleted from function.bcscale by danbrown

From: Date: Thu, 20 May 2010 03:08:04 +0000
Subject: note 98001 deleted from function.bcscale by danbrown
References: 1  Groups: php.notes 
Request: Send a blank email to php-notes+get-169440@lists.php.net to get a copy of this message
Note Submitter: codeslinger at compsalot dot com ---- 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.

« previous php.notes (#169440) next »