Re: printf scientific notation?
| From: | Bill Rausch | Date: | Fri, 05 Oct 2001 15:47:20 +0000 |
| Subject: | Re: printf scientific notation? | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-70100@lists.php.net to get a copy of this message | ||
Thank Richard.
So far, I just punted. My site runs on a dedicated box and doesn't have to service a lot of users so I just wrote a one line C program to print a single value using a specified format (default is %.4e) and use exec() to call it.
printe [format] value
Here's how I encapsulated it:
function printe( $x )
{
$lines = array();
exec( "/usr/local/bin/printe \"".$x."\"", $lines );
return $lines[0];
}
and an example of how I call the function:
fputs( $fp, sprintf( "%8.2f %s %s\n", $this->O_a_time[$i],
printe($this->O_a_height[$i]),
printe($this->O_a_cooling[$i]) ) );
It works well enough for now. Eventually I hope to have time to play and then I'll come back and figure out a real patch for PHP's printf to support %e directly.
Bill
At 12:09 AM -0500 10/5/01, Richard Lynch wrote:
You could roll your own... % and (int) / and round() are all you need. ----- Original Message ----- From: Bill Rausch <bill@numerical.com> Subject: printf scientific notation? Can PHP print floating point numbers using scientific notation?-- Bill Rausch, Software Development, Unix, Mac, Windows Numerical Applications, Inc. 509-943-0861 bill@numerical.com(like 1.32e+5) sscanf reads them ok using %f, but I'd like to print them with %e or %g and the printf documentation doesn't mention them.I've tried %e anyway and it fails to print the exponent part.