Computer Webmaster Gaming Console Graphics Forum

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.

MK PitStop Main Earn $25 Earn Money Posting Extras Members Blogs Image Hosting User Pages
Go Back   Computer Webmaster Gaming Console Graphics Forum > Webmaster Forum > Website Coding > PHP
Register FAQ/Rules Become A V.I.P. Member Search Today's Posts Mark Forums Read

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.

Google
Reply
 
LinkBack Thread Tools Display Modes
Old 05-20-2007, 5:33 PM   #1
shortbackandsides.no@spam.hairdresser.net
 
shortbackandsides.no@spam.hairdresser.net's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Currency rounding

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)?
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Advertisements
Old 05-20-2007, 5:33 PM   #2
ZeldorBlat
 
ZeldorBlat's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Currency rounding

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>

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 05-20-2007, 5:33 PM   #3
shortbackandsides.no@spam.hairdresser.net
 
shortbackandsides.no@spam.hairdresser.net's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Currency rounding

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.

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 05-20-2007, 5:33 PM   #4
shimmyshack
 
shimmyshack's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Currency rounding

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

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 05-20-2007, 5:33 PM   #5
Geoff Berrow
 
Geoff Berrow's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Currency rounding

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
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 05-20-2007, 5:33 PM   #6
shimmyshack
 
shimmyshack's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Currency rounding

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

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 05-20-2007, 5:33 PM   #7
Geoff Berrow
 
Geoff Berrow's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Currency rounding

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
 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Old 05-20-2007, 5:33 PM   #8
shortbackandsides.no@spam.hairdresser.net
 
shortbackandsides.no@spam.hairdresser.net's Avatar
 
Posts: n/a
My Photos: (0)

Banked:
MK Cash: $

I am Worth:
MK Cash: $
Donate

Recent Blog: None

Default Currency rounding

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!

 
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit!
Reply With Quote
Featured Websites
Free Space
Free Space
Free Space Free Space
Reply
Tags: ,




Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


Featured Websites




All times are GMT +1. The time now is 7:39 PM.


Powered by: vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
LinkBacks Enabled by vBSEO 3.0.0
Cheap Computers
MK PitStop Copyright 2005 - 2008

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98