VirtueMart Forum

VirtueMart 2 + 3 + 4 => Virtuemart Development and bug reports => Topic started by: hazael on December 21, 2022, 11:36:10 AM

Title: round(): Argument #1 ($num) must be of type int|float, string given
Post by: hazael on December 21, 2022, 11:36:10 AM
It is not possible to create a new price in a product calculated on the basis of the gross price.
The problem disappears when I first add the net price
An error occurs

round(): Argument #1 ($num) must be of type int|float, string given

VirtueMart 4.0.10 10767 / Joomla 3 / PHP8.1
Title: Re: round(): Argument #1 ($num) must be of type int|float, string given
Post by: Kuubs on August 05, 2023, 20:02:24 PM
You can fix this by changing the function to this:

/**
* Standard round function, we round every number with 6 fractionnumbers
* We need at least 4 to calculate something like 9.25% => 0.0925
* 2 digits
* Should be setable via config (just for the crazy case)
*/
function roundInternal($value, $name = 0) {
    $value = (float) $value; // Ensure value is a float

    if (empty($value)) {
        if ($value === null) {
            vmTrace('Why we try to round a null value?');
            $value = 0.0;
        }
        return $value;
    }

    if (!$this->_roundindig and $name !== 0) {
        if (isset($this->_currencyDisplay->_priceConfig[$name][1])) {
            $precision = (int) $this->_currencyDisplay->_priceConfig[$name][1]; // Ensure precision is an int
            // vmdebug('roundInternal rounding '.$name.' use '.$precision.' digits');
            return round($value, $precision);
        } else {
            $precision = (int) $this->_currencyDisplay->_priceConfig['salesPrice'][1]; // Ensure precision is an int
            // vmdebug('roundInternal rounding not found for '.$name.' use salesPrice');
            return round($value, $precision);
        }
    } else {
        return round($value, $this->_internalDigits);
    }
}
Title: Re: round(): Argument #1 ($num) must be of type int|float, string given
Post by: Milbo on August 09, 2023, 19:50:06 PM
Thank you, added.