Division by zero.

This commit is contained in:
Ivor Barhansky 2023-08-10 17:11:27 +03:00
parent deac9203bd
commit e4bf3fd342

View File

@ -2,6 +2,7 @@
namespace Model;
use Core\Config;
use Core\Db;
class EkrExchangeRates
@ -14,23 +15,29 @@ class EkrExchangeRates
public function __construct()
{
$this->today = Db::getRow('select RUB, USD, from_unixtime(id, ?) as date from ekr_exchange_rates order by id desc limit 1', ['%d.%m.%Y']);
if (empty($this->today)) {
$this->today = ['RUB' => 0, 'USD' => 0, 'date' => '00.00.0000'];
}
}
public function oneEkrInUSD(): float
{
if (!$this->today) {
return 0.00;
}
return round($this->today['RUB'] / $this->today['USD'], 2);
}
public function oneEkrInRUB(): float
{
if (!$this->today) {
return floatval(Config::EKR_RUB_PRICE);
}
return $this->today['RUB'];
}
public function date(): string
{
if (!$this->today) {
return date('d.m.Y');
}
return $this->today['date'];
}
}