Zen Follower
- Join Date:
- Feb 2017
- Location:
- Tokyo, Japan
- Posts:
- 334
- Plugin Contributions:
- 0
rounding values <0
ZC: 2.1.0
PHP: 8.2.29
DB: MySQL 11.8.3-MariaDB-1+b1 from Debian
site: https://www.proteawines.jp/shop/
While editing products, I inadvertently set "Product Qty Units" instead of "Products Quantity" to 4 ("Product Qty Minimum" is 1, "Product Qty Maximum" is 0), resulting in some fractional internal calculation and the error message:
PHP Fatal error: Uncaught TypeError: Unsupported operand types: string * int in /<redacted>/includes/functions/functions_general_shared.php:56
Stack trace:
#0 /<redacted>/includes/modules/preview_info.php(80): fmod_round()
#1 /<redacted>/product.php(118): require('...')
#2 /<redacted>/index.php(16): require('...')
#3 {main}
thrown in /<redacted>/includes/functions/functions_general_shared.php on line 56
This comes from using the following function in "includes/functions/functions_general_shared.php":
function fmod_round($x, $y)
{
if ($y == 0) {
return 0;
}
$x = (string)$x;
$y = (string)$y;
$zc_round = ($x * 1000) / ($y * 1000);
$zc_round_ceil = round($zc_round, 0);
$multiplier = $zc_round_ceil * $y;
$results = abs(round($x - $multiplier, 6));
return $results;
}
It seems this code is quite old, but I see it is still in the current github codebase.
PHP 8 seems to have stricter type checking and no longer permits this. As an experiment I tried to cast as float:
$zc_round = ((float)$x * 1000) / ((float)$y * 1000);
``` but that had no effect apparently.
Zen Cart 1.5.6c modified for Japanese language support. Upgraded incrementally from initial 1.5.5d. Currently planning direct upgrade to 2.1.0