PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!
Moderator: General Moderators
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Thu Jul 13, 2006 11:43 am
How would I convert a number from 0.420049480000000E+02 format to a float or double?
Last edited by
Luke on Thu Jul 13, 2006 1:36 pm, edited 1 time in total.
pickle
Briney Mod
Posts: 6445 Joined: Mon Jan 19, 2004 6:11 pm
Location: 53.01N x 112.48W
Contact:
Post
by pickle » Thu Jul 13, 2006 12:13 pm
Break it up & do some math. I'm kind of guessing here, but doesn't that number = 42.004948 or does it =0.0042004948 or does it = something else my feeble intellect can't comprehend?
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Thu Jul 13, 2006 12:15 pm
pickle wrote: 42.004948
I believe this is correct. I was just wondering if there was a built-in function... the math isn't difficult, but I figured why reinvent the wheel? I'll just do the math I guess. Thanks man.
Ollie Saunders
DevNet Master
Posts: 3179 Joined: Tue May 24, 2005 6:01 pm
Location: UK
Post
by Ollie Saunders » Thu Jul 13, 2006 12:49 pm
The Ninja Space Goat wrote: How would I convert a number from 0.420049480000000E+02 format to a float or double?
You might want to test but even for dodgy string like 0.420049480000000E+02 i think this should work:
Code: Select all
$var = '0.420049480000000E+02';
$floatVar = (float)$var;
PHP definately supports scientific notation.
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Thu Jul 13, 2006 1:35 pm
no, (float) didn't do it... made it 0... and settype turned it into a 1. Any other suggestions?
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Thu Jul 13, 2006 1:44 pm
The Ninja Space Goat wrote: no, (float) didn't do it... made it 0... and settype turned it into a 1. Any other suggestions?
did it for me:
Code: Select all
$var = '0.420049480000000E+02';
$floatVar = (float)$var;
var_dump(phpversion());
var_dump($floatVar);
// string(5) "5.1.2"
// float(42.004948)
// string(5) "4.4.2"
// float(42.004948)
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Thu Jul 13, 2006 1:47 pm
maybe it's because mine is stored in the database with quotes around it like "-0.122525406135743E+03"
This sounds really stupid, but I didn't get much sleep last night... how do I get rid of those quotes?
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Thu Jul 13, 2006 1:51 pm
nevermind I got it
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Thu Jul 13, 2006 1:57 pm
Roja
Tutorials Group
Posts: 2692 Joined: Sun Jan 04, 2004 10:30 pm
Post
by Roja » Thu Jul 13, 2006 2:11 pm
*SERIOUSLY* impressive. VERY cool.
So cool, *I* didn't even look at the viewsource/validation! Seriously, very cool work. Congrats!
Luke
The Ninja Space Mod
Posts: 6424 Joined: Fri Aug 05, 2005 1:53 pm
Location: Paradise, CA
Post
by Luke » Thu Jul 13, 2006 2:15 pm
thanks man... I appreciate that. seriously.
Weirdan
Moderator
Posts: 5978 Joined: Mon Nov 03, 2003 6:13 pm
Location: Odessa, Ukraine
Post
by Weirdan » Thu Jul 13, 2006 2:27 pm
I DID IT!!!!
Eh... and what does it do? Drawing curves on google maps?
Roja
Tutorials Group
Posts: 2692 Joined: Sun Jan 04, 2004 10:30 pm
Post
by Roja » Thu Jul 13, 2006 2:31 pm
Weirdan wrote: I DID IT!!!!
Eh... and what does it do? Drawing curves on google maps?
Outlines counties based on coordinate lists.
Ollie Saunders
DevNet Master
Posts: 3179 Joined: Tue May 24, 2005 6:01 pm
Location: UK
Post
by Ollie Saunders » Thu Jul 13, 2006 2:52 pm
Outlines counties based on coordinate lists.
Oh wow that is impressive. Not that hard though, I imagine.