$code])); $codeCorrect = sizeof($result) < 0; } while ($codeCorrect); return $code; } // Convertir vers le multiple de 5 le plus proche function roundUpToAny($n, $x = 5) { return (ceil($n) % $x === 0) ? ceil($n) : round(($n + $x / 2) / $x) * $x; } private function convertMoney($amount, $sourceCurrency, $targetCurrency) { // set to whatever your rates are relative to $baseCurrency = 'USD'; // use your own credentials, or re-use your existing PDO connection $pdo = new PDO('mysql:host=' . env('DB_HOST') . ';dbname=' . env('DB_DATABASE'), env('DB_USERNAME'), env('DB_PASSWORD')); $configuration = new PDOProviderConfiguration( tableName: 'exchange_rate', exchangeRateColumnName: 'exchange_rate', sourceCurrencyCode: $baseCurrency, targetCurrencyColumnName: 'target_currency' ); // this provider loads exchange rates from your database $provider = new PDOProvider($pdo, $configuration); // this provider calculates exchange rates relative to the base currency $provider = new BaseCurrencyProvider($provider, $baseCurrency); $converter = new CurrencyConverter($provider); $sourceMoney = Money::of(round($amount, 2), $sourceCurrency, new AutoContext()); return $converter->convert($sourceMoney, $targetCurrency, null, RoundingMode::UP); } public function toMoneyAmount($amount, $sourceCurrency, $targetCurrency) { return $this->convertMoney($amount, $sourceCurrency, $targetCurrency)->getAmount()->toFloat(); } }