您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

CurrencyConverter.php 806B

123456789101112131415161718192021222324
  1. <?php
  2. namespace App\Utilities\Currency;
  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. public static function convertBalance($balance, $oldCurrency, $newCurrency): int
  16. {
  17. return money($balance, $oldCurrency)->swapAmountFor($newCurrency);
  18. }
  19. }