sRound example



        if (!empty($result[CartKey::POSITIONS])) {
            foreach ($result[CartKey::POSITIONS] as $key => $value) {
                if (!empty($value['amountWithTax'])) {
                    $t = round((float) str_replace(',', '.', $value['amountWithTax']), 2);
                } else {
                    $t = str_replace(',', '.', $value['price']);
                    $t = (float) round($t * $value['quantity'], 2);
                }
                if (!$this->sSYSTEM->sUSERGROUPDATA['tax'] && $this->sSYSTEM->sUSERGROUPDATA['id']) {
                    $p = (float) $this->moduleManager->Articles()->sRound(
                        $this->moduleManager->Articles()->sRound(round($value['netprice'], 2) * $value['quantity'])
                    );
                } else {
                    $p = (float) $this->moduleManager->Articles()->sRound(
                        $this->moduleManager->Articles()->sRound($value['netprice'] * $value['quantity'])
                    );
                }
                $calcDifference = $this->moduleManager->Articles()->sFormatPrice($t - $p);
                $result[CartKey::POSITIONS][$key]['tax'] = $calcDifference;
            }
        }

        
/** * Formats product prices * * @param float $price * * @return string */
    public function sFormatPrice($price)
    {
        $price = str_replace(',', '.', (string) $price);
        $price = $this->sRound($price);
        $price = str_replace('.', ',', (string) $price); // Replaces points with commas         $commaPos = strpos((string) $price, ',');
        if ($commaPos) {
            $part = substr((string) $price$commaPos + 1, \strlen((string) $price) - $commaPos);
            switch (\strlen($part)) {
                case 1:
                    $price .= '0';
                    break;
                case 2:
                    break;
            }
        }
Home | Imprint | This part of the site doesn't use cookies.