|
Posted by shimmyshack on 05/15/07 01:36
On May 14, 8:15 pm, shortbackandsides...@spam.hairdresser.net wrote:
> On 14 May 2007 09:07:52 -0700, ZeldorBlat <zeldorb...@gmail.com>
> wrote:
>
>
>
> >On May 14, 12:01 pm, shortbackandsides...@spam.hairdresser.net wrote:
> >> This snippet:
> >> <?php
> >> $price=round(111,2);
> >> $tax=round($price*0.175,2);
> >> $total=round($price*1.175,2);
>
> >> echo $price <br />";
> >> echo "Tax at 17.5% $tax<br />";
> >> echo "Total $total<br />";
> >> ?>
> >> gives the result:
>
> >> 111
> >> Tax at 17.5% 19.42
> >> Total 130.43
>
> >> Two questions.
> >> Why the rounding difference?
> >> and is there a standard function to force the 111 to display as 111.00
> >> (given that price won't always be a whole number)?
>
> >When I run your code on my system I get 19.43 and 130.43. It could be
> >a platform or library issue -- I'm running PHP 5.1.6 on Fedora Core 6
> >Linux.
>
> >As for your other question, you can force the display of the zeros
> >using either number_format() or money_format():
>
> ><http://www.php.net/number_format>
> ><http://www.php.net/money_format>
>
> Thanks ZeldorBlat, it must be my PHP version that's the problem
> (4.4.2) - money/number formats don't help either so it looks like time
> for some fancy footwork with string manipulations.
also in the UK tax is found by flooring not rounding. ie 17.5% of £1
is 17.5p but the tax is only 17p
[Back to original message]
|