Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Avoid rounding issues #903

Merged
merged 3 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion inc/utils.php
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,11 @@ function mollieWooCommerceFormatCurrencyValue($value, $currency)
if (in_array($currency, $currenciesWithNoDecimals)) {
return number_format($value, 0, '.', '');
}

// trying to avoid floating point issues
$value = $value * 1000;
$value = (int) $value / 1000; //drop the last decimal after the third
$value = round($value, 3);
$value = round($value, 2, PHP_ROUND_HALF_DOWN); //round down, as seems woo like it :)
return number_format($value, 2, '.', '');
}

Expand Down
2 changes: 1 addition & 1 deletion src/Payment/OrderLines.php
Original file line number Diff line number Diff line change
Expand Up @@ -560,7 +560,7 @@ private function get_shipping_vat_rate()
{
$shipping_vat_rate = 0;
if (WC()->cart->shipping_tax_total > 0) {
$shipping_vat_rate = round(WC()->cart->shipping_tax_total / WC()->cart->shipping_total, 2) * 100;
$shipping_vat_rate = round(WC()->cart->shipping_tax_total / WC()->cart->shipping_total, 4) * 100;
}

return $shipping_vat_rate;
Expand Down
Loading