Re: scientific notation?

From: Date: Fri, 03 Aug 2001 22:32:05 +0000
Subject: Re: scientific notation?
References: 1  Groups: php.general 
Request: Send a blank email to php-general+get-61196@lists.php.net to get a copy of this message
> Does anyone know how to force numerics into scientific notation? I > noticed that %e doesn't exist in the PHP implementations of s/printf. http://php.net/number_format may have that... If all else fails... # Untested code: function scientific_format($number){ $base = $number; $mantissa = 0; if ($base < 0){ while ($base < -1){ $base *= 10; $mantissa--; } while ($base > -1){ $base /= 10; $mantissa++; } } else{ while ($base < 1){ $base *= 10; $mantissa--; } while ($base > 1){ $base /= 10; $mantissa++; } } $output = $base; if ($mantissa){ $output .= "E$mantissa"; } return $output; } No promises on this code doing anything remotely like IEEE standards... If you need that, look into BC_MATH. -- WARNING richard@zend.com address is an endangered species -- Use ceo@l-i-e.com Wanna help me out? Like Music? Buy a CD: http://l-i-e.com/artists.htm Volunteer a little time: http://chatmusic.com/volunteer.htm

« previous php.general (#61196) next »