Re: printf and number_format rounding
| From: | Richard Lynch | Date: | Thu, 04 May 2006 09:49:50 +0000 |
| Subject: | Re: printf and number_format rounding | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-235458@lists.php.net to get a copy of this message | ||
On Wed, May 3, 2006 12:25 pm, Duffy, Scott E wrote:
> 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.
http://php.net/substring might do what you want.
You'll have to calculate the decimal point for yourself and work from
there.
--
Like Music?
http://l-i-e.com/artists.htm