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 Link to comment https://forums.phpfreaks.com/topic/93665-reading-sceintific-notation/ 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>"; ?> Link to comment https://forums.phpfreaks.com/topic/93665-reading-sceintific-notation/#findComment-480380 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.