Forums / Currencies & Sales Taxes, VAT, GST, etc. / Europe : rounding tax to nearest .5 cents (eliminate pennies)

Europe : rounding tax to nearest .5 cents (eliminate pennies)

Started by nan on 14 Feb 2008, 10:54 AM · Views: 11,961

Results 1 to 16 of 16
14 Feb 2008, 10:54 AM
#1
nan avatar

nan

New Zenner

Join Date:
Feb 2008
Posts:
5
Plugin Contributions:
0

Europe : rounding tax to nearest .5 cents (eliminate pennies)

live in switzerland where penny/1 cent is nonexistant, so i need to find a way to get the TVA VAT tax to automaticall round to the nearest .0 or .5 or .55. does anyone have some advice?
found this block of code in functions and also simlar in classes and it seems like it could be here to find a solution but after a few tests can't figure it out:

// Calculates Tax rounding the result
function zen_calculate_tax($price, $tax) {
global $currencies;
// $result = bcmul($price, $tax, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
// $result = bcdiv($result, 100, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
// return $result;
return zen_round($price * $tax / 100, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
}

14 Feb 2008, 11:34 AM
#2
schoolboy avatar

schoolboy

Totally Zenned

Join Date:
Jun 2005
Location:
Cumbria, UK
Posts:
10,327
Plugin Contributions:
0

Re: Europe : rounding tax to nearest .5 cents (eliminate pennies)

Not sure if this will work, but try it...

ADMIN >>> LOCALISATION >>> CURRENCIES

Select the relevant currency, click EDIT.

Set DECIMAL PLACES to "1".

20 years a Zencart User

14 Feb 2008, 11:41 AM
#3
nan avatar

nan

New Zenner

Join Date:
Feb 2008
Posts:
5
Plugin Contributions:
0

Re: Europe : rounding tax to nearest .5 cents (eliminate pennies)

tnaks for your reply. i tried that already and it works to some extent but what about when a price ot tax should display as for example 22.55?

14 Feb 2008, 11:42 AM
#4
nan avatar

nan

New Zenner

Join Date:
Feb 2008
Posts:
5
Plugin Contributions:
0

Re: Europe : rounding tax to nearest .5 cents (eliminate pennies)

sorry, dyslexic typist :-)

14 Feb 2008, 11:56 AM
#5
schoolboy avatar

schoolboy

Totally Zenned

Join Date:
Jun 2005
Location:
Cumbria, UK
Posts:
10,327
Plugin Contributions:
0

Re: Europe : rounding tax to nearest .5 cents (eliminate pennies)

nan:

live in switzerland where penny/1 cent is nonexistant, so i need to find a way to get the TVA VAT tax to automaticall round to the nearest .0 or .5 or .55. does anyone have some advice?
found this block of code in functions and also simlar in classes and it seems like it could be here to find a solution but after a few tests can't figure it out:

// Calculates Tax rounding the result
function zen_calculate_tax($price, $tax) {
global $currencies;
// $result = bcmul($price, $tax, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
// $result = bcdiv($result, 100, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
// return $result;
return zen_round($price * $tax / 100, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
}

// return $result;
return zen_round($price * $tax / 100, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);

Try changing to 10

I'm NO CODER - so I could be taking you far from where you want to be! Also, changing this will have a GLOBAL effect on all selected currencies.

20 years a Zencart User

14 Feb 2008, 11:57 AM
#6
schoolboy avatar

schoolboy

Totally Zenned

Join Date:
Jun 2005
Location:
Cumbria, UK
Posts:
10,327
Plugin Contributions:
0

Re: Europe : rounding tax to nearest .5 cents (eliminate pennies)

I think that what you actually need could be a bit of javascript, for example, that rounds this up (or down) as you suggest.

But I can't help you there!

20 years a Zencart User

22 Sep 2009, 12:27 AM
#7
dutchkiwis avatar

dutchkiwis

New Zenner

Join Date:
Sep 2008
Posts:
20
Plugin Contributions:
0

Re: Europe : rounding tax to nearest .5 cents (eliminate pennies)

Hi there,

Did you have any luck finding a solution to get zencart rounding to the nearest 5 cts?

Cheers,
Ed

22 Sep 2009, 1:16 AM
#8
dutchkiwis avatar

dutchkiwis

New Zenner

Join Date:
Sep 2008
Posts:
20
Plugin Contributions:
0

Re: Europe : rounding tax to nearest .5 cents (eliminate pennies)

Hello fellow Zenners,

I am desparately seeking hellp on a TAX/VAT rounding for a Swiss zencart (1.3.8). Apparently the Swiss do not use rappen( pennies, cents). In stead they round their totals to the nearest 5 cts. No amount less than 5 cents in cash or paid in the invoice. See details below

I spend a good few hours looking into the problem and trawling forums (even those of OSC) but no simple and consistent solution is available.

My cart is already configured with net prices and all prices are multiples of 5 already. Thus, the only thing I need is rounding of the tax component in both the catalog and admin section.

How do I do this? Where do I need to hook in? Your suggestions are most welcome.

Some more info on the rounding:

Crucial to the rounding is the middle between 0 and 5 cents, respectively 5 to the nearest 10 cents. If the number to be rounded is equal to or higher than the middle, the number is rounded up, otherwise it's are rounded down.

Beispiel: Example:

* 1,000–1,024 → 1,00 1,000-1,024 → 1.00
* 1,025–1,074 → 1,05 1,025-1,074 → 1.05
* 1,075–1,099 → 1,10 1,075-1,099 → 1.10 

Suggested method: round(((amount+0.000001)*2),1) / 2;

22 Sep 2009, 6:24 AM
#9
schoolboy avatar

schoolboy

Totally Zenned

Join Date:
Jun 2005
Location:
Cumbria, UK
Posts:
10,327
Plugin Contributions:
0

Re: Europe : rounding tax to nearest .5 cents (eliminate pennies)

In the following code (posted earlier)...

// Calculates Tax rounding the result
function zen_calculate_tax($price, $tax) {
global $currencies;
// $result = bcmul($price, $tax, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
// $result = bcdiv($result, 100, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
// return $result;
return zen_round($price * $tax / 100, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']);
} 

... all of the lines preceded with "// have no effect as they are commented.

The line that says:

return zen_round($price * $tax / 100, $currencies->currencies[DEFAULT_CURRENCY]['decimal_places']); 

Change:
$tax / 100
to
$tax / 20

I really don't know if this will work, but my logic is that 100 divided by 20 is 5 - and as you are looking for a rounding factor of 5, then dividing by 20 may give you the desired result.

In your currency setting in Admin, leave the number of decimal places at 2.

20 years a Zencart User

22 Sep 2009, 9:08 AM
#10
tino_schlegel avatar

tino_schlegel

Totally Zenned

Join Date:
Nov 2007
Location:
Melbourne, Australia
Posts:
532
Plugin Contributions:
0

Re: Europe : rounding tax to nearest .5 cents (eliminate pennies)

If you want to have all currencies round to 5 cents its the easiest when you change the zen_round() function in

/includes/functions/functions_general.php

line 173 - 179

// Wrapper function for round()
  function zen_round($number, $precision) {
/// fix rounding error on GVs etc.
    $number = round($number / 5, $precision) * 5;

    return $number;
  }

Replace the entire function or add the highlighted sections.

24 Sep 2009, 12:24 PM
#11
dutchkiwis avatar

dutchkiwis

New Zenner

Join Date:
Sep 2008
Posts:
20
Plugin Contributions:
0

Re: Europe : rounding tax to nearest .5 cents (eliminate pennies)

Works for me !!! Big thanks.

In effect the rounding is applied to all number calculations. I just needed to final VAT field to behave. I wonder if there is a more elegant way of resolving rounding.

1 Nov 2010, 2:18 PM
#12
cocolala avatar

cocolala

New Zenner

Join Date:
Jan 2010
Posts:
31
Plugin Contributions:
0

Re: Europe : rounding tax to nearest .5 cents (eliminate pennies)

tino.schlegel:

If you want to have all currencies round to 5 cents its the easiest when you change the zen_round() function in

/includes/functions/functions_general.php

line 173 - 179

// Wrapper function for round()
function zen_round($number, $precision) {
/// fix rounding error on GVs etc.
$number = round($number / 5, $precision) * 5;

return $number;

}

> 
> Replace the entire function or add the highlighted sections.


this is helpful. prices in website are showing correctly as well as invoice to customers. however, invoice in admin is showing without rounding to nearest 5 cents. any solution?
4 Nov 2010, 7:58 AM
#13
cocolala avatar

cocolala

New Zenner

Join Date:
Jan 2010
Posts:
31
Plugin Contributions:
0

Re: Europe : rounding tax to nearest .5 cents (eliminate pennies)

// Wrapper function for round()
function zen_round($number, $precision) {
/// fix rounding error on GVs etc.
$number = round($number / 5, $precision) * 5;

return $number;

}

I have done the above to /includes/functions/functions_general.php
and it shows correctly in my website.

However, the invoice at admin>order is showing without rounding off.

I then add the above to the file myadmin/includes/functions/functions_general.php, the Price (inc) is showing with round off but Price (ex) is not.

FYI I don't set tax for my products.

Please advise.

29 Jan 2011, 6:34 AM
#14
cocolala avatar

cocolala

New Zenner

Join Date:
Jan 2010
Posts:
31
Plugin Contributions:
0

Re: Europe : rounding tax to nearest .5 cents (eliminate pennies)

another problem i found is, after rounding off to nearest 5 cents, the total value might be incorrect.

eg.
subtotal 23.40 (actual 23.39)
shipping 8.65 (actual 8.63)
total 32.00 (actual 32.02)

any solution?

13 Jun 2017, 1:46 PM
#15
marton_1 avatar

marton_1

Totally Zenned

Join Date:
Apr 2013
Location:
eglisau switzerland
Posts:
568
Plugin Contributions:
0

Re: Europe : rounding tax to nearest .5 cents (eliminate pennies)

tino.schlegel:

If you want to have all currencies round to 5 cents its the easiest when you change the zen_round() function in

/includes/functions/functions_general.php

line 173 - 179

// Wrapper function for round()
function zen_round($number, $precision) {
/// fix rounding error on GVs etc.
$number = round($number / 5, $precision) * 5;

return $number;

}

> 
> Replace the entire function or add the highlighted sections.

Just did this change in 155d and it seems to work fine.
In this 155 version the code to change is on lines 214 - 220!

I am curious that the change has the variable $number whereas the code to be replaced has $value; could this change cause unexpected consequences?

Thanks for any advice!
1 Sep 2017, 8:12 AM
#16
marton_1 avatar

marton_1

Totally Zenned

Join Date:
Apr 2013
Location:
eglisau switzerland
Posts:
568
Plugin Contributions:
0

Re: Europe : rounding tax to nearest .5 cents (eliminate pennies)

marton_1:

Just did this change in 155d and it seems to work fine.
In this 155 version the code to change is on lines 214 - 220!

I am curious that the change has the variable $number whereas the code to be replaced has $value; could this change cause unexpected consequences?

Thanks for any advice!

I just noticed when a customer pays with PayPal then they pay the correct "unrounded" amount. So if, for example, the unrounded amount is 50.03 and the invoice shows 50.05 then they pay 50.03.

It would be nice for the customer to pay the invoice amount especially as in Switzerland prices in cents have to be multiples of 5; so 5, 10, 15 etc.
I just have to find the correct file to insert

 $number = round($number / 5, $precision) * 5;

    return $number; 

Having said that PayPal works OK with these "illegal" amounts.