Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

CurrencyConverter.php 622B

123456789101112131415161718
  1. <?php
  2. namespace App\Utilities;
  3. class CurrencyConverter
  4. {
  5. public static function convertAndSet($newCurrency, $oldCurrency, $amount): ?string
  6. {
  7. if ($newCurrency === null || $oldCurrency === $newCurrency) {
  8. return null;
  9. }
  10. $old_attr = currency($oldCurrency);
  11. $new_attr = currency($newCurrency);
  12. $temp_balance = str_replace([$old_attr->getThousandsSeparator(), $old_attr->getDecimalMark()], ['', '.'], $amount);
  13. return number_format((float)$temp_balance, $new_attr->getPrecision(), $new_attr->getDecimalMark(), $new_attr->getThousandsSeparator());
  14. }
  15. }