Skip to content

Commit

Permalink
dev
Browse files Browse the repository at this point in the history
  • Loading branch information
skeeks-semenov committed Jul 26, 2022
1 parent 868b8f0 commit b5f6b4a
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
* @property integer subUnit
*
* @property float baseCourse
* @property string symbol
*
* new Currency('RUB');
*
Expand Down Expand Up @@ -1262,7 +1263,7 @@ public function getSubUnit()
//return (integer)$this->model->sub_unit;
}

return (integer) ArrayHelper::getValue($this->_baseData, 'sub_unit');
return (integer)ArrayHelper::getValue($this->_baseData, 'sub_unit');
}

/**
Expand Down Expand Up @@ -1307,4 +1308,18 @@ public function getCurrencyCode()
{
return $this->code;
}

/**
* @param $locale
* @return false|string
*/
function getSymbol($locale = '')
{
if (!$locale) {
$locale = \Yii::$app->formatter->locale;
}

$formatter = new \NumberFormatter($locale.'@currency='.$this->code, \NumberFormatter::CURRENCY);
return $formatter->getSymbol(\NumberFormatter::CURRENCY_SYMBOL);
}
}
6 changes: 6 additions & 0 deletions src/Money.php
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,13 @@ public function jsonSerialize()
{
return [
'amount' => (float) $this->amount,
'amountFormat' => \Yii::$app->formatter->asDecimal($this->amount),

'amountRound' => (float) round($this->amount, 2),
'amountRoundFormat' => \Yii::$app->formatter->asDecimal((float) round($this->amount, 2)),

'currency' => $this->currency->code,
'convertSymbol' => $this->currency->symbol,
'convertAndFormat' => \Yii::$app->money->convertAndFormat($this),
];
}
Expand Down

0 comments on commit b5f6b4a

Please sign in to comment.