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 . " * 10<sup>".$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

Reply via email to