Re: printf and number_format rounding
| From: | Barry | Date: | Thu, 04 May 2006 10:15:15 +0000 |
| Subject: | Re: printf and number_format rounding | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-235463@lists.php.net to get a copy of this message | ||
Richard Lynch schrieb:
On Wed, May 3, 2006 12:25 pm, Duffy, Scott E wrote:Probably it will help you: function addtax($price,$tax) {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. I use this function to add tax to a price.
bcscale(6);
$calc = bcmul(bcdiv($price,100,6),bcadd(100,$tax,6),6);
$output = bcadd (0,$calc,2);
$roundarray = explode (".",$calc);
if (substr($roundarray[1],2,1) >= 5)
{
$output = $roundarray[0]+(substr($roundarray[1],0,2)/100)+0.01;
}
else $output = $roundarray[0]+(substr($roundarray[1],0,2)/100)+0.0;
return $output;
}
--
Smileys rule (cX.x)C --o(^_^o)
Dance for me! ^(^_^)o (o^_^)o o(^_^)^ o(^_^o)