# Re: [PHP] Move Decimal Point

```Ok...I tried this code but...all it does is take up all my RAM and crash the
browser... I don't quite see what I'm doing wrong with it:```
```
\$i = 1;
\$exp = 0;
do {
\$num /= 10;
list(\$whole, \$nothing) = explode(".", \$num);
if(ereg('^[0-9.]+\$', \$whole))
{
\$i = 2;
}
else
{
\$exp++;
\$i = 1;
}
} while(\$i = 1);
\$output = \$num . "* 10<sup>".\$exp."</sup>";

----- Original Message -----
From: "1LT John W. Holmes" <[EMAIL PROTECTED]>
To: "Stephen" <[EMAIL PROTECTED]>
Cc: "PHP List" <[EMAIL PROTECTED]>
Sent: Wednesday, December 11, 2002 4:40 PM
Subject: Re: [PHP] Move Decimal Point

: > > >I have a question. How would you move the decimal left or right,
: > > depending on if the
: > > >number a user enters is negative or not, and then move it that many
: > > spaces? If
: > > >needed, it would add zeros.
: > >
: > > Hmm. Trying to remember what grade I learned this in. You multiply by
10
: > > to move it right, divide by 10 to move it left.
: >
: > The way we were just now taught (I'm in 7th grade Pre-Algebra) was using
: > exponets. To move it to the right, we take 10 to the so and so power. To
: the
: > left we do 10 to the negative power of so and so. So...I just answered
my
: > own question... Im go to assume that will work as well. But one part is
:
: So we are helping you do your homework?
:
: > > >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.
: > >
: > > Treat it as a string and look for the first set of double zeros.
: >
: > Yes... I could do this... But what if the number is 2.5000435000 or
: > whatever?
:
: And what do you want to do if that's the number?
:
: > What I need to do is this. The user specifies a number, let's say
0.0046.
: > What the script needs to do, is take that number, and print it out in
: > scientific notation. So the answer for 0.0046 would be 4.6 x 10 ^-3.
From
: my
: > notes it says:
: >
: >     All numbers expressed in scientific notation are given as the
product
: of
: > a number between 1 and 10 and a power of 10.
:
: Well, a couple ways you could do it. You could multiply/divide the number
by
: 10 until it's between 1 and 10, keeping track of how many times you
: multiplied/divided and that'll be your exponent.
:
: So 0.0046 would be multiplied by 10 three times to get 4.6 and you'd turn
: your 3 into 10^-3, resulting in 4.6x10^-3.
: 240000.00 would be divided by 10 five times to get 2.4 * 10^5
:
: Or you could use some regular expressions or regular string expressions to
: find the length of the number, trucate it to how ever many digits you want
: and find out what your exponent is.
:
: ---John Holmes...
:
:
:

--
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php

```