better counting

This commit is contained in:
2022-04-01 12:26:34 +02:00
parent 6b005cb5b6
commit 7e55e5097f
5 changed files with 94 additions and 35 deletions
+37 -8
View File
@@ -2,17 +2,20 @@
declare(strict_types=1);
namespace App\Logic\Crypto;
use App\Helper\Currency;
use phpDocumentor\Reflection\DocBlock\Tags\Var_;
class MainObject
{
const _CRYPTO_DIVIDER = 10000000;
private \DateTime $dateTime;
private string $desc;
private string $value;
private int $value;
private string $currency;
private ?string $realCurrency=null;
private float $realValue=0;
private int $realValue=0;
private float $price=0;
private bool $isCrypto = false;
/**
* @return float
@@ -23,9 +26,9 @@ class MainObject
}
/**
* @param float $realValue
* @param int $realValue
*/
public function setRealValue(float $realValue): void
public function setRealValue(int $realValue): void
{
$this->realValue = $realValue;
}
@@ -81,7 +84,7 @@ class MainObject
/**
* @return int
*/
public function getValue(): string
public function getValue(): int
{
return $this->value;
}
@@ -89,7 +92,7 @@ class MainObject
/**
* @param int $value
*/
public function setValue(string $value): void
public function setValue(int $value): void
{
$this->value = $value;
}
@@ -107,6 +110,9 @@ class MainObject
*/
public function setCurrency(string $currency): void
{
if (!in_array($currency, Currency::$currencies)) {
$this->isCrypto = true;
}
$this->currency = $currency;
}
@@ -125,7 +131,18 @@ class MainObject
public function takePrice() : void
{
$this->price = floatval(abs(round($this->realValue / $this->getValue(),4)));
$real = $this->getRealValue() / 100;
$val = $this->getValue();
if ($this->isCrypto) {
$val = $this->getValueCrypto();
}
$price = round($real/$val,8);
// if ($this->isCrypto) {
// $price *= self::_CRYPTO_DIVIDER;
// } else {
// $price *= 100;
// }
$this->price = $price;
}
public function getPrice() : float
@@ -135,6 +152,18 @@ class MainObject
public function getValueCrypto() : float
{
return intval($this->value) / 100000000;
return $this->value / self::_CRYPTO_DIVIDER;
}
public function subtract(MainObject $mainObject)
{
$this->value = $this->getValue() - $mainObject->getValue();
}
public function checkCurrency() : void
{
if (!$this->isCrypto) {
$this->value = intval($this->value/self::_CRYPTO_DIVIDER*100);
}
}
}