The Tools::ps:round function rounds to 0 precision if no parameter is sent.
The function should round to precision chosen in config, as it is written in the comment for the function.
Thanks for opening this issue! We will help you to keep its state consistent
Hi @PrestaworksNiklas and thanks for your report.
I confirm the function is malformed and need to be a little refactored.
https://github.com/PrestaShop/PrestaShop/blob/1.7.7.x/classes/Tools.php#L1897
The Tools::$round_mode property shouldn't be public nor set in cache.
/**
* Returns the rounded value of $value to specified precision, according to your configuration;.
*
* @param float $value
* @param int $precision
* @param int $round_mode
*
* @return float
*/
public static function ps_round($value, $precision = 0, $round_mode = null)
{
if ($round_mode === null) {
$round_mode = (int) Configuration::get('PS_PRICE_ROUND_MODE');
}
switch ($round_mode) {
case PS_ROUND_UP:
return Tools::ceilf($value, $precision);
case PS_ROUND_DOWN:
return Tools::floorf($value, $precision);
case PS_ROUND_HALF_DOWN:
case PS_ROUND_HALF_EVEN:
case PS_ROUND_HALF_ODD:
return Tools::math_round($value, $precision, $round_mode);
case PS_ROUND_HALF_UP:
default:
return Tools::math_round($value, $precision, PS_ROUND_HALF_UP);
}
}
@PrestaShop/prestashop-core-developers What do you think?
I think this function should be deprecated in favor of Decimal.
Most helpful comment
I think this function should be deprecated in favor of Decimal.