Use BigDecimal for Currency exchange rate.

This commit is contained in:
Jan Böhmer 2020-05-20 20:57:16 +02:00
parent 08267b88b0
commit db4d7dc5fc
9 changed files with 135 additions and 20 deletions

View file

@ -43,6 +43,7 @@ declare(strict_types=1);
namespace App\Command;
use App\Entity\PriceInformations\Currency;
use Brick\Math\BigDecimal;
use function count;
use Doctrine\ORM\EntityManagerInterface;
use Exchanger\Exception\Exception;
@ -122,10 +123,11 @@ class UpdateExchangeRatesCommand extends Command
//Iterate over each candidate and update exchange rate
foreach ($candidates as $currency) {
/** @var Currency $currency */
try {
$rate = $swap->latest($currency->getIsoCode().'/'.$this->base_current);
$currency->setExchangeRate((string) $rate->getValue());
$io->note(sprintf('Set exchange rate of %s to %f', $currency->getIsoCode(), $currency->getExchangeRate()));
$currency->setExchangeRate(BigDecimal::of($rate->getValue()));
$io->note(sprintf('Set exchange rate of %s to %f', $currency->getIsoCode(), $currency->getExchangeRate()->toFloat()));
$this->em->persist($currency);
++$success_counter;