![]() |
|
Welcome to the Computer Webmaster Gaming Console Graphics Forum forums. You are currently viewing our boards as a guest which gives you limited access to view most discussions and access our other features. By joining our free community you will have access to post topics, communicate privately with other members (PM), respond to polls, upload content and access many other special features. Registration is fast, simple and absolutely free so please, join our community today! If you have any problems with the registration process or your account login, please contact contact us. |
| |||||||
| PHP PHP for some can be one of the hardest website programming codes, so do you need help on your PHP script, if it is php4, php5 or lower this is the place for you for any PHP help. |
![]() |
| | LinkBack | Thread Tools | Display Modes |
| | #1 | ||
| 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)? | |||
|
| Advertisements |
| | #2 | ||
| 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> | |||
|
| | #3 | ||
| On 14 May 2007 09:07:52 -0700, ZeldorBlat <zeldorblat@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. | |||
|
| | #4 | ||
| 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 | |||
|
| | #5 | ||
| Message-ID: <1179193009.883361.18060@q75g2000hsh.googlegroups. com> from shimmyshack contained the following: >> 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. Same here on 4.3.9 > >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 I didn't know that. Have you got a reference? -- Geoff Berrow 0110001001101100010000000110 001101101011011001000110111101100111001011 100110001101101111001011100111010101101011 | |||
|
| | #6 | ||
| On May 15, 7:15 am, Geoff Berrow <blthe...@ckdog.co.uk> wrote: > Message-ID: <1179193009.883361.18060@q75g2000hsh.googlegroups. com> from > shimmyshack contained the following: > > >> 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. > > Same here on 4.3.9 > > > > >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 > > I didn't know that. Have you got a reference? > -- > Geoff Berrow 0110001001101100010000000110 > 001101101011011001000110111101100111001011 > 100110001101101111001011100111010101101011 OT. In retail it is more complicated than just round down to nearest penny!! anyway this from the uk tax website: 17.5.1 Calculation based on lines of goods or services If you wish to work out the VAT separately for a line of goods or services, which are included with other goods or services in the same invoice, you should calculate the separate amounts of VAT either by rounding: * down to the nearest 0.1p - for example, 86.76p would be rounded down to 86.7p; or * to the nearest 1p or 0.5p - for example, 86.76p would be rounded up to 87p. Whatever you decide, you must be consistent. The final total amount of VAT payable may be rounded down to the nearest whole penny. http://customs.hmrc.gov.uk/channelsP...543#P574_44405 | |||
|
| | #7 | ||
| Message-ID: <1179228680.850019.193580@k79g2000hse.googlegroups .com> from shimmyshack contained the following: >OT. > >In retail it is more complicated than just round down to nearest >penny!! Yes it is!. Thanks for the info. -- Geoff Berrow 0110001001101100010000000110 001101101011011001000110111101100111001011 100110001101101111001011100111010101101011 | |||
|
| | #8 | ||
| On Tue, 15 May 2007 13:21:36 +0100, Geoff Berrow <blthecat@ckdog.co.uk> wrote: >Message-ID: <1179228680.850019.193580@k79g2000hse.googlegroups .com> from >shimmyshack contained the following: > >>OT. >> >>In retail it is more complicated than just round down to nearest >>penny!! > > And we tripped over a shopping cart issue where rounding meant that buying 10 items ended up costing a penny more than buying the ten individually, inevitably someone spotted it and complained (yes, about a one penny difference!) The difference happens depending on whether you do the calculation (item cost + vat) x 10 or (item cost x 10)+vat Tax man is happy with either as long as you are consistent. As for rounding down - oh bugger I'd just persuaded my script to round both figures up consistently! | |||
|
| Featured Websites | ||||
|
![]() |
| Tags: currency, rounding |
| Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
| Thread Tools | |
| Display Modes | |
| |
| Featured Websites | ||||
|