From 5d82556f9a62039953d33a394463dc42b149e89a Mon Sep 17 00:00:00 2001 From: Dennis Eichhorn Date: Thu, 3 Mar 2016 11:59:05 +0100 Subject: [PATCH] Update Money.php --- Localization/Money.php | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/Localization/Money.php b/Localization/Money.php index 8b1378917..a69667358 100644 --- a/Localization/Money.php +++ b/Localization/Money.php @@ -1 +1,42 @@ + ISO4270::{$currency}) { + $decimals = ISO4270::{$currency}; + } + + $value = (string) round($value, - 5 + $decimals); + + $left = substr($value, 0, -5); + $right = substr($value, -5); + + return ($decimals > 0) : number_format($left, 0, $thousands, $decimal); . $decimal . $right : (string) $left; + } + + private static function getFromString(string $value, string $currency, string $thousands = ',', string $decimal = '.', int $decimals = 2) : int + { + if($decimals > ISO4270::{$currency}) { + $decimals = ISO4270::{$currency}; + } + + $split = explode($value, $decimal); + + $left = ''; + $left = $split[0]; + $left = str_replace($thousands, '', $left); + + $rigth = ''; + if(count($split) > 1) { + $right = $split[1]; + } + + $right = substr($right, 0, -5); + $value = (int) round((int) $left + (int) $right, - 5 + $decimals); + + return $value; + } +}