RE: [PHP] Move Decimal Point

2002-12-11 Thread John W. Holmes
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.

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. 

---John W. Holmes...

PHP Architect - A monthly magazine for PHP Professionals. Get your copy
today. http://www.phparch.com/




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




Re: [PHP] Move Decimal Point

2002-12-11 Thread Chris Wesley
On Wed, 11 Dec 2002, Stephen wrote:

 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.

Math ... multiply  divide ... I assume you're using a base-10 number
system, so multiply or divide by 10 when your user's input indicates you
should do so.

 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.

I have one for you first.  Are you using this list to do your homework?
I've noticed that over the past couple days you've been asking
not-necessarily PHP questions, but /basic/ programming questions.

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.

g.luck,
~Chris


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




Re: [PHP] Move Decimal Point

2002-12-11 Thread Stephen
 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
still unanswered:


 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?

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.

Hope this helps and you can answer my question!



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




Re: [PHP] Move Decimal Point

2002-12-11 Thread Hugh Bothwell
Chris Wesley [EMAIL PROTECTED] wrote in message
[EMAIL PROTECTED]">news:[EMAIL PROTECTED]...
 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++;
}




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




Re: [PHP] Move Decimal Point

2002-12-11 Thread 1LT John W. Holmes
  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
 still unanswered:

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.
24.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




Re: [PHP] Move Decimal Point

2002-12-11 Thread Stephen
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 . * 10sup.$exp./sup;

Please help!

- 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
:  still unanswered:
:
: 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.
: 24.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




Re: [PHP] Move Decimal Point...Again

2002-12-11 Thread Stephen
Side note...the formatting for my email program went all weird. The numbers
I'm getting as error are as follows:

4.6E-009 * 10^6
1.7E-006

^ indicates that the next number is an exponent... The real error does not
show the ^ sign.

- Original Message -
From: Stephen [EMAIL PROTECTED]
To: PHP List [EMAIL PROTECTED]
Sent: Wednesday, December 11, 2002 7:11 PM
Subject: [PHP] Move Decimal Point...Again


: Ok, nevermind about that. I fixed it finally. However, I am having trouble
: with the negative exponents. I want to find the scientific notation of
: 0.0046 which should be 4.6 * 10 to the negative 3rd. However, what I get
in
: return is this:
:
: 4.6E-009 * 106
:
: How could I fix this problem? I'm also having it for getting the standard
: form of 1.7 * 10 to the negative 6th. I get this: 1.7E-006
:
: Here's my code for finding the scientific notation:
:
:   $num = $_POST['num'];
:   $pos[0] = strpos($num, 1);
:   $pos[1] = strpos($num, 2);
:   $pos[2] = strpos($num, 3);
:   $pos[3] = strpos($num, 4);
:   $pos[4] = strpos($num, 5);
:   $pos[5] = strpos($num, 6);
:   $pos[6] = strpos($num, 7);
:   $pos[7] = strpos($num, 8);
:   $pos[8] = strpos($num, 9);
:   array_multisort($pos, SORT_DESC);
:   $exp = 0;
:   $position = $pos[0] + 1;
:   do {
:$num /= 10;
:$exp++;
:   } while($exp  $position);
:   $output = $num .  * 10sup.$exp./sup;
:   echo $output;
:
: Here's the code for finding the standard form:
:
:   $num = $_POST['num'];
:   $exp = $_POST['power'];
:   $output = $num * pow(10, $exp);
:
: Please help me! I'm lost!!
:
:
:
: --
: PHP General Mailing List (http://www.php.net/)
: To unsubscribe, visit: http://www.php.net/unsub.php
:
:
:



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