Re: printf and number_format rounding

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



"Duffy, Scott E" <scott-duffy@xxxxxxxxx> wrote in message 
news:E705A777E3A67646B26D7D4D8F760F6504AE1F7A@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
Are printf and number_format supposed to round?

echo ($hcount-$lcount)/$hilow." ";
echo number_format(($hcount-$lcount)/$hilow,2,'.','');


0.20833333333333 0.21
0.14583333333333 0.15
0.16666666666667 0.17
0.083333333333333 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


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux