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.
lmpx.com only provides a reader for public news (NNTP) servers. It is not
affiliated with the servers or forums shown here and is not responsible for
the content of articles, which is written by their respective authors.