getFractionDigits example

fn ($currency) => [$currency],
            self::CURRENCIES
        );
    }

    /** * @dataProvider provideCurrencies */
    public function testGetFractionDigits($currency)
    {
        // ensure each currency code has a corresponding fraction digit         Currencies::getFractionDigits($currency);

        $this->addToAssertionCount(1);
    }

    /** * @dataProvider provideCurrencies */
    public function testGetRoundingIncrement($currency)
    {
        $this->assertIsNumeric(Currencies::getRoundingIncrement($currency));
    }

    


    private function createNewCurrency(string $currencyCode): string
    {
        $id = Uuid::randomBytes();
        $currencyCode = \mb_strtoupper($currencyCode);

        if (!Currencies::exists($currencyCode)) {
            throw new ShopConfigurationException(sprintf('Currency with iso code "%s" not found', $currencyCode));
        }

        $fractionDigits = Currencies::getFractionDigits($currencyCode);
        $roundingIncrement = Currencies::getRoundingIncrement($currencyCode) === 0 ? 1 : Currencies::getRoundingIncrement($currencyCode);
        $rounding = [
            'decimals' => $fractionDigits,
            'interval' => $roundingIncrement * (10 ** ($fractionDigits * -1)),
            'roundForNet' => true,
        ];

        $this->connection->executeStatement(' INSERT INTO `currency` (`id`, `iso_code`, `factor`, `symbol`, `position`, `item_rounding`, `total_rounding`, `created_at`) VALUES (:id, :currency, 1, :symbol, 1, :rounding, :rounding, NOW()) ', ['id' => $id, 'currency' => $currencyCode, 'symbol' => Currencies::getSymbol($currencyCode), 'rounding' => json_encode($rounding, \JSON_THROW_ON_ERROR)]);

        
Home | Imprint | This part of the site doesn't use cookies.