News:

You may pay someone to create your store, or you visit our seminar and become a professional yourself with the silver certification

Main Menu

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

Started by hazael, December 21, 2022, 11:36:10 AM

Previous topic - Next topic

hazael

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

Kuubs

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);
    }
}

Milbo

Should I fix your bug, please support the VirtueMart project and become a member
______________________________________
Extensions approved by the core team: http://extensions.virtuemart.net/