ultrus Posted August 19, 2008 Share Posted August 19, 2008 Hello, I'm playing around with the Yale Bright Star Catalog, thinking of the best way to convert the E notation provided into decimal numbers. I know how to do it the hard way by parsing the string and doing the math. Is there a pre-built function for this though?: -9.7205E-01 = -.97205 2.3496E+01= 23.496 -1.3808E+01 = -13.808 Thanks for the feedback. Link to comment https://forums.phpfreaks.com/topic/120355-solved-is-there-a-fast-way-to-convert-e-notation-to-decimal-example-97205e-01/ Share on other sites More sharing options...
PFMaBiSmAd Posted August 19, 2008 Share Posted August 19, 2008 echo rtrim(sprintf("%f", -9.7205E-01),"0") . "<br />"; echo rtrim(sprintf("%f", 2.3496E+01),"0") . "<br />"; echo rtrim(sprintf("%f", -1.3808E+01),"0") . "<br />"; Link to comment https://forums.phpfreaks.com/topic/120355-solved-is-there-a-fast-way-to-convert-e-notation-to-decimal-example-97205e-01/#findComment-620113 Share on other sites More sharing options...
ultrus Posted August 19, 2008 Author Share Posted August 19, 2008 PFMaBiSmAd, You the man! That helps simplify things a lot. A have to parse a file with over 28,000 of those, and that should save some time. Thank you, Link to comment https://forums.phpfreaks.com/topic/120355-solved-is-there-a-fast-way-to-convert-e-notation-to-decimal-example-97205e-01/#findComment-620182 Share on other sites More sharing options...
PFMaBiSmAd Posted August 19, 2008 Share Posted August 19, 2008 The number of course can be in a variable, so a loop could be used. Link to comment https://forums.phpfreaks.com/topic/120355-solved-is-there-a-fast-way-to-convert-e-notation-to-decimal-example-97205e-01/#findComment-620199 Share on other sites More sharing options...
ultrus Posted August 19, 2008 Author Share Posted August 19, 2008 Yep yep. I plan on looping through each line of a file, getting and converting numbers, and adding to a database. I could just imagine the pain involved in converting each number one at a time. ouch! Thanks Link to comment https://forums.phpfreaks.com/topic/120355-solved-is-there-a-fast-way-to-convert-e-notation-to-decimal-example-97205e-01/#findComment-620224 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.