/    Sign up×
Community /Pin to ProfileBookmark

Wierd Sci. notation format…

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!

to post a comment
PHP

3 Comments(s)

Copy linkTweet thisAlerts:
@GarySSep 28.2006 — Might be worth having a looking at this: http://uk2.php.net/sprintf
Copy linkTweet thisAlerts:
@stephan_gerlachSep 28.2006 — if you want to split the number into those two parts you can use the following

[code=php]

//$number = 6.8394048239E-011;

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

[/code]
Copy linkTweet thisAlerts:
@stalepretzel59authorOct 11.2006 — 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
×

Success!

Help @stalepretzel59 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.29,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...