Re: Move Decimal Point
| From: | Hugh Bothwell | Date: | Wed, 11 Dec 2002 20:38:14 +0000 |
| Subject: | Re: Move Decimal Point | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-127894@lists.php.net to get a copy of this message | ||
"Chris Wesley" <cwwesley@udlug.org> wrote in message
news:Pine.LNX.4.44.0212110954430.16786-100000@leftcoast.thebackrow.net...
> On Wed, 11 Dec 2002, Stephen wrote:
>
> > One other question. How would I find the first 0 of a repeating zero.
> > Like 204,000. How would you find the 0 in the 4th column.
>
> For your repeating zeors question, you'll have to make use of some string
> functions or a regexp function. Look for a pattern of more than 1 zero.
I would check out the modulus operator (%); something
like the following:
$zeros = 0;
// Ensure the number is an integer (if
// you already know this, you can skip
// this step).
// NOTE: no overflow checking!
while ($number != (int) $number) {
$zeros--;
$number *= 10;
}
// Look for trailing 0s
while(($number % 10) == 0) {
$number /= 10;
$zeros++;
}