Jump to content

Reading Sceintific Notation


m1tch37

Recommended Posts

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

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>";
?>

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.