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']);
}
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".
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?
Re: Europe : rounding tax to nearest .5 cents (eliminate pennies)
sorry, dyslexic typist :-)
Re: Europe : rounding tax to nearest .5 cents (eliminate pennies)
Quote:
Originally Posted by
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.
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!
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
How to round TAX/VAT the swiss way?
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;
Re: Europe : rounding tax to nearest .5 cents (eliminate pennies)
In the following code (posted earlier)...
PHP Code:
// 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:
PHP Code:
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.
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
Code:
// 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.
Re: How to round TAX/VAT the swiss way?
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.
Re: Europe : rounding tax to nearest .5 cents (eliminate pennies)
Quote:
Originally Posted by
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
Code:
// 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?
Sale Price: Round off to nearest 5 cents
// 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.
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?
Re: Europe : rounding tax to nearest .5 cents (eliminate pennies)
Quote:
Originally Posted by
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
Code:
// 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!
Re: Europe : rounding tax to nearest .5 cents (eliminate pennies)
Quote:
Originally Posted by
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
Code:
$number = round($number / 5, $precision) * 5;
return $number;
Having said that PayPal works OK with these "illegal" amounts.