Click to See Complete Forum and Search --> : Wierd Sci. notation format...


stalepretzel59
09-26-2006, 03:41 PM
Hey all, I have a problem with the computer's display of really large or small numbers with scientific notation. I am making a "Gravity Calculator" and the answer will often be very large or small. The computer displays these numbers as 6.8394048239E-011. Well, that may be okay for a computer nerd, but the public generally doesn't want to try to decipher that mess of numbers. So what can i do? I have one idea, which I think will work. I just want an opinion before i go about solving the problem.
I think i should convert the ugly number into a text string. then i could use javascript (or php?) to sort the ugly number into two parts: 6.8394048239 and -011 (or -11?). This could pretty easily be transfered into understandable scientific notation. Any better ideas? Brainstorm with me!
Thanks in advace!

GaryS
09-28-2006, 04:58 AM
Might be worth having a looking at this: http://uk2.php.net/sprintf

stephan.gerlach
09-28-2006, 06:15 AM
if you want to split the number into those two parts you can use the following



//$number = 6.8394048239E-011;

$num_arr = explode('E',$number);

stalepretzel59
10-10-2006, 09:23 PM
Ok, that the "$part = explode('E','$number')" command looks very helpful... now we have $part[0]=6.8394048239 and $part[1]=-011. Now can't we say a variable $exp=-011 and then the computer will change that to -11? then if the exponent were to be possitive, it would just return 11, without the pos/neg sign or the extra zero. Am i makiing sense? basically this would turn 6.839...E-011 to {$part[0]= 6.839...} and $exp =-11}. it would turn 6.839...E+011 into {$part[0]=6.839...} and {$exp=11}.
Please correct me if im wrong!
Thanks,
St. Pretzel