From 1d2151cd83ff75beb0a5bbbeb385f098538a03eb Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Tue, 9 Aug 2016 15:47:47 +0200 Subject: [PATCH] Revert localization change --- Localization/Money.php | 40 +++++++++++++++++++++++++++++++++++++++- 1 file changed, 39 insertions(+), 1 deletion(-) diff --git a/Localization/Money.php b/Localization/Money.php index 08a6f0cad..080a697d7 100644 --- a/Localization/Money.php +++ b/Localization/Money.php @@ -67,15 +67,38 @@ class Money implements \Serializable * @param string|int|float $value Value * @param string $thousands Thousands separator * @param string $decimal Decimal separator + * @param string $symbol Currency symbol + * @param int $position Symbol position * * @since 1.0.0 * @author Dennis Eichhorn */ - public function __construct($value = 0, string $thousands = ',', string $decimal = '.') + public function __construct($value = 0, string $thousands = ',', string $decimal = '.', string $symbol = '', int $position = 0) { $this->value = is_int($value) ? $value : self::toInt((string) $value); $this->thousands = $thousands; $this->decimal = $decimal; + $this->symbol = $symbol; + $this->position = $position; + } + + /** + * Set localization. + * + * @param string $thousands Thousands separator + * @param string $decimal Decimal separator + * @param string $symbol Currency symbol + * @param int $position Symbol position + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function setLocalization(string $thousands = ',', string $decimal = '.', string $symbol = '', int $position = 0) + { + $this->thousands = $thousands; + $this->decimal = $decimal; + $this->symbol = $symbol; + $this->position = $position; } /** @@ -143,6 +166,21 @@ class Money implements \Serializable return ($decimals > 0) ? number_format($left, 0, $this->decimal, $this->thousands) . $this->decimal . substr($right, 0, $decimals) : (string) $left; } + /** + * Get money. + * + * @param int $decimals Precision + * + * @return string + * + * @since 1.0.0 + * @author Dennis Eichhorn + */ + public function getCurrency(int $decimals = 2) : string + { + return ($position === 0 ? $smbol : '') . $this->getAmount($decimals, $thousands, $decimal) . ($position === 1 ? $smbol : ''); + } + /** * Add money. *