Always round to precision. Negate need to call get_tax_total to handle rounding. Instead it just sums.

This commit is contained in:
Mike Jolley 2019-01-11 12:38:05 +00:00
parent 11d14b30a4
commit af3707d75a
1 changed files with 18 additions and 4 deletions

View File

@ -150,6 +150,13 @@ class WC_Tax {
$taxes[ $key ] += $tax_amount; $taxes[ $key ] += $tax_amount;
} }
/**
* Round all taxes to precision (4DP) before passing them back. Note, this is not the same rounding
* as in the cart calculation class which, depending on settings, will round to 2DP when calculating
* final totals. Also unlike that class, this rounds .5 up for all cases.
*/
$taxes = array_map( array( __CLASS__, 'round' ), $taxes );
return $taxes; return $taxes;
} }
@ -200,6 +207,13 @@ class WC_Tax {
} }
} }
/**
* Round all taxes to precision (4DP) before passing them back. Note, this is not the same rounding
* as in the cart calculation class which, depending on settings, will round to 2DP when calculating
* final totals. Also unlike that class, this rounds .5 up for all cases.
*/
$taxes = array_map( array( __CLASS__, 'round' ), $taxes );
return $taxes; return $taxes;
} }
@ -710,13 +724,13 @@ class WC_Tax {
} }
/** /**
* Round tax lines and return the sum. Note this rounds to precision, not store currency decimals. * Sums a set of taxes to form a single total. Values are pre-rounded to precision from 3.6.0.
* *
* @param array $taxes Array of taxes to round. * @param array $taxes Array of taxes.
* @return float * @return float
*/ */
public static function get_tax_total( $taxes ) { public static function get_tax_total( $taxes ) {
return array_sum( array_map( array( __CLASS__, 'round' ), $taxes ) ); return array_sum( $taxes );
} }
/** /**