mirror of
https://github.com/Karaka-Management/phpOMS.git
synced 2026-01-11 17:58:41 +00:00
Objectify
This commit is contained in:
parent
2438bd28da
commit
f397142aab
|
|
@ -5,27 +5,25 @@ namespace phpOMS\Localization;
|
|||
class Money {
|
||||
|
||||
const DECIMALS = 5;
|
||||
|
||||
private static function getFromInt(int $value, string $currency = 'USD', string $thousands = ',', string $decimal = '.', int $decimals = 2) : string
|
||||
|
||||
private $currency = 'USD';
|
||||
private $thousands = ',';
|
||||
private $decimal = '.';
|
||||
|
||||
private $value = 0;
|
||||
|
||||
public function __construct(string $currency = 'USD', string $thousands = ',', string $decimal = '.')
|
||||
{
|
||||
if($decimals > ISO4270::{$currency}) {
|
||||
$decimals = ISO4270::{$currency};
|
||||
}
|
||||
|
||||
$value = (string) round($value, - self::DECIMALS + $decimals);
|
||||
|
||||
$left = substr($value, 0, -self::DECIMALS);
|
||||
$right = substr($value, -self::DECIMALS);
|
||||
|
||||
return ($decimals > 0) : number_format($left, 0, $thousands, $decimal); . $decimal . $right : (string) $left;
|
||||
$this->currency = $currency;
|
||||
$this->thousands = $thousands;
|
||||
$this->decimal = $decimal;
|
||||
}
|
||||
|
||||
public function setInt(int $value) {
|
||||
$this->value = $value;
|
||||
}
|
||||
|
||||
private static function getFromString(string $value, string $currency = 'USD', string $thousands = ',', string $decimal = '.', int $decimals = 2) : int
|
||||
{
|
||||
if($decimals > ISO4270::{$currency}) {
|
||||
$decimals = ISO4270::{$currency};
|
||||
}
|
||||
|
||||
public function setString(string $value) {
|
||||
$split = explode($value, $decimal);
|
||||
|
||||
$left = '';
|
||||
|
|
@ -38,8 +36,20 @@ class Money {
|
|||
}
|
||||
|
||||
$right = substr($right, 0, -self::DECIMALS);
|
||||
$value = (int) round((int) $left + (int) $right, - self::DECIMALS + $decimals);
|
||||
|
||||
return $value;
|
||||
$this->value = (int) round((int) $left + (int) $right, - self::DECIMALS + $decimals);
|
||||
}
|
||||
|
||||
public function getAmount(int $decimals = 2) : string
|
||||
{
|
||||
if($decimals > ISO4270::{$currency}) {
|
||||
$decimals = ISO4270::{$currency};
|
||||
}
|
||||
|
||||
$value = (string) round($value, - self::DECIMALS + $decimals);
|
||||
|
||||
$left = substr($value, 0, -self::DECIMALS);
|
||||
$right = substr($value, -self::DECIMALS);
|
||||
|
||||
return ($decimals > 0) : number_format($left, 0, $this->thousands, $this->decimal); . $decimal . $right : (string) $left;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue
Block a user