25 lines
461 B
PHP
25 lines
461 B
PHP
<?php declare(strict_types=1);
|
|
|
|
namespace App\ValueObject;
|
|
|
|
use Stringable;
|
|
|
|
class Money implements Stringable {
|
|
private readonly float $value;
|
|
|
|
public function __construct(mixed $value)
|
|
{
|
|
$this->value = (float) str_replace(['$', ','], '', (string) $value);
|
|
}
|
|
|
|
public function __toString(): string
|
|
{
|
|
return (string) $this->getValue();
|
|
}
|
|
|
|
public function getValue(): float
|
|
{
|
|
return (float) str_replace(['$', ','], '', (string) $this->value);
|
|
}
|
|
}
|