Aplikasi Keuangan yang mengatur lalu lintas transaksi antara bank dan aplikasi internal Kampus
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 

35 lines
830 B

<?php
namespace App\Domains\Finance\Support\ValueObjects;
use InvalidArgumentException;
use NumberFormatter;
use Stringable;
class Money implements Stringable
{
public function __construct(public float $amount)
{
if ($this->amount < 0) {
throw new InvalidArgumentException('Money cannot be negative.');
}
}
/**
* Format the bytes into a human-readable string.
*/
public function format(string $currency = 'IDR'): string
{
$format = new NumberFormatter(app()->getLocale(), NumberFormatter::CURRENCY);
return $format->formatCurrency($this->amount, $currency);
}
/**
* Automatically format when echoed in Blade (e.g., {{ $model->amount }}).
*/
public function __toString(): string
{
return $this->format();
}
}