[PHP] Re: printf and number_format rounding
"Duffy, Scott E" <[EMAIL PROTECTED]> wrote in message news:[EMAIL PROTECTED] Are printf and number_format supposed to round? echo ($hcount-$lcount)/$hilow." "; echo number_format(($hcount-$lcount)/$hilow,2,'.',''); 0.208333 0.21 0.145833 0.15 0.17 0.17 0.083 0.08 Printf ("%.2f",($hcount-$lcount)/$hilow); Does the same. It would appear to be. If there is a function to print just to the digit could you point me in the direction? So I would want 0.20 0.14 0.16 0.08 respectively. --- You could have the number_format return an extra digit, and then strip that extra digit off. $str = number_format(($hcount-$lcount)/$hilow,3,'.',''); $str = substr($str, 0, 4); // (something like this) DanB -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: printf() in a variable, or alternative to printf()
sprintf() http://php.net/manual/en/function.sprintf.php -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: printf
figured that out as well You need to put the number_format($number,2) afterwards Thanks to both you! "Ron Allen" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > I am looking at how to format output > > Here is what I have. There is a simple currency conversion that I do and > the output is just a string of numbers > I would like it so that it puts a comma for every 3 spaces...Any > clues..oh knowing newsgroup > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: printf
Figured out why it wasn't working, but I need to be able to display the 2 decimals afterwards "Ron Allen" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > I am looking at how to format output > > Here is what I have. There is a simple currency conversion that I do and > the output is just a string of numbers > I would like it so that it puts a comma for every 3 spaces...Any > clues..oh knowing newsgroup > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: printf
This is what I have and it is not working $converted1 =round($usdamount * $convamount, 2); $converted = number_format($converted1); //echo "$amount * $convamount = $converted"; echo "You should receive$nbsp $converted $currency"; "Ron Allen" <[EMAIL PROTECTED]> wrote in message [EMAIL PROTECTED]">news:[EMAIL PROTECTED]... > I am looking at how to format output > > Here is what I have. There is a simple currency conversion that I do and > the output is just a string of numbers > I would like it so that it puts a comma for every 3 spaces...Any > clues..oh knowing newsgroup > > -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: printf
Use number_format() to put a comma between the thousands $foo = 123456789; print number_format($foo); //will print 123,456,789 Ron Allen wrote: > I am looking at how to format output > > Here is what I have. There is a simple currency conversion that I do and > the output is just a string of numbers > I would like it so that it puts a comma for every 3 spaces...Any > clues..oh knowing newsgroup -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: printf
In article <[EMAIL PROTECTED]>, [EMAIL PROTECTED] says... > I am looking at how to format output > > Here is what I have. There is a simple currency conversion that I do and > the output is just a string of numbers > I would like it so that it puts a comma for every 3 spaces...Any > clues..oh knowing newsgroup number_format() -- David Robley Temporary Kiwi! Quod subigo farinam -- PHP General Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php
[PHP] Re: printf scientific notation?
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 <[EMAIL PROTECTED]> >Subject: printf scientific notation? > > > Can PHP print floating point numbers using scientific notation? >> (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. -- Bill Rausch, Software Development, Unix, Mac, Windows Numerical Applications, Inc. 509-943-0861 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
[PHP] Re: printf scientific notation?
You could roll your own... % and (int) / and round() are all you need. -- WARNING [EMAIL PROTECTED] address is an endangered species -- Use [EMAIL PROTECTED] 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 - Original Message - From: Bill Rausch <[EMAIL PROTECTED]> Newsgroups: php.general To: <[EMAIL PROTECTED]> Sent: Wednesday, October 03, 2001 10:40 AM Subject: printf scientific notation? > I'll try this again, with a new topic and a better description. > > Can PHP print floating point numbers using scientific notation? > (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. > > I've looked at the source code to PHP a little but with the IFDEFs > I'm not sure which routine is actually being used. I sort of have the > impression it is just calling the C routines directly so the %e and > %g should work? > > Linux (RH 7.1), Apache (1.3.20), PHP (4.0.6) > > Thanks. > -- > Bill Rausch, Software Development, Unix, Mac, Windows > Numerical Applications, Inc. 509-943-0861 [EMAIL PROTECTED] -- PHP General Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]