How can I set to not round the discounts in the order?

  • Posts: 10
  • Thank you received: 0
  • Hikashop Business
1 year 11 months ago #347739

-- HikaShop version -- : 4.7.0
-- Joomla version -- : 3.9.23
-- PHP version -- : 7.3.33

Hi support,

I've set Round prices during calculations to "NO" in the backend but even still the discounts are being rounded up.
I have a 1% coupon to all products and a 3% discount in the payment method (bank transfer) as an option.
How can I set to not round the discounts in the order?

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
1 year 11 months ago #347741

Hi,

Prices are always rounded. It doesn't make sense to display an amount at 9.999999€ for example.
So HikaShop will round any amount being displayed based on the rounding settings of the currency being used. So if you configure the rounding to be at 2 decimals in your currency, then no matter if the amount displayed is a discount, a tax, a shipping fee, a product price or something else, if the amount is 9.999999... it will be rounded to 10.00€.
The "Round prices during calculations" setting is to choose to round amounts during the calculations and when displaying the amounts, or only when displaying the amounts.
For example, suppose I have a product priced at 10€ with a discount at 33.33333%. The discounted amount would be 3.333333
With the setting activated, this amount would be rounded 3.33. Then, suppose I'm buying a 100 of these products.
That would be a total discount of 3.33 * 100 = 333 for a grand total of 667€.
With that setting turned off, the total discount would be 333.33333 displayed as 333.33 for a grand total of 666.67€
Both modes of calculations are correct. It depends on the rules you set for yourself. For example, PayPal makes its calculations similarly to HikaShop when the setting is activated. Most accounting software make their calculations similarly to HikaShop when the setting is turned off.

So to go back to your question: I'm not sure what you mean. Do you mean that you set a rounding of 0 in your currency but you want discounts to be displayed with a rounding of 2 decimals ? That's not possible. In that case, you want to set the rounding to 2 in the currency and all the amounts will display with a rounding of 2 decimals. But then the question is why you did this in the first place ? Maybe there is another solution to what you were trying to do ? Or maybe you're talking about something totally different and I would need more details to understand your situation and what you're trying to achieve to be able to answer.

Please Log in or Create an account to join the conversation.

  • Posts: 10
  • Thank you received: 0
  • Hikashop Business
1 year 10 months ago #347812

Hi support,

What I meant was that the system is rounding up with the discount.

For instance it should be like this:

total $103.63
Discount (1%) 1.0363 -> -1.03

The system displays like this: -1.04

Is it possible to avoid this? Let me know how, please.

Please Log in or Create an account to join the conversation.

  • Posts: 82863
  • Thank you received: 13372
  • MODERATOR
1 year 10 months ago #347813

Hi,

Well, rounding normally works like that:
When you have 0.001, 0.002, 0.003 or 0.004, rounding it to 2 decimals means it would output 0.00.
When you have 0.006, 0.007, 0.008 or 0.009, rounding it to 2 decimals means it would output 0.01.
So it's normal the system displays -1.04 for -1.0363 as that's how rounding normally works. You can read more about rounding numbers here:
www.mathsisfun.com/rounding-numbers.html

Now, it is possible to change the way rounding works in PHP:
www.php.net/manual/en/function.round.php
The round function (which we use in HikaShop) has a third argument you can use to change the mode for 0.005.
If you want to change it, you can change the line:
return round($price, $round);
For example, you could change it to:
return round($price, $round, PHP_ROUND_HALF_DOWN);
in the file administrator/components/com_hikashop/classes/currency.php

But even so, it doesn't handle truncate. So for example, you can't have 1.039, or 1.036 to output 1.03 with that function. So, in your example, it wouldn't change what is displayed. If you want to achieve a truncate instead of a rounding, you would have to add a truncate function like:

function truncate($number, $precision = 2)
{
    $fig = (int) str_pad('1', $precision, '0');
    return (floor($number * $fig) / $fig);
}
and use that function instead of the round function of PHP there.
However, I don't recommend it. This will affect all calculations, including tax calculations. Also, I think it might not be legally allowed to do that in some countries. So before changing the way the rounding is done, I would recommend you to check with your accountant what they suggest.

Last edit: 1 year 10 months ago by nicolas.

Please Log in or Create an account to join the conversation.

Time to create page: 0.062 seconds
Powered by Kunena Forum