m1tch37 Posted February 29, 2008 Share Posted February 29, 2008 I have a very small variable (10^-13) and when i print it it prints as: 3.93293670343E-013 I was wondering if there is such a function to expand it to return the exponent and the coefficient. Say for example: list($exp,$co) = sciexpand($smallnum); print $co." x 10<sup>".$exp."</sup>"; Would output: 3.93293670343 x 10-13 Is such a function around? Cheers, Mitch Quote Link to comment Share on other sites More sharing options...
fnairb Posted February 29, 2008 Share Posted February 29, 2008 I don't know that there is a native function but this seems to work. Note: the return value is reverse of your example. <?php function sci_expand($sci) { settype($sci, 'string'); return explode('E', $sci); } list ($co, $exp) = sci_expand(3.93293670343E-013); print "{$co}x10<sup>{$exp}</sup>"; ?> Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.