Skip to content

Commit

Permalink
Merge pull request #3 from superchlastac/master
Browse files Browse the repository at this point in the history
add decimal places
  • Loading branch information
thorewi authored Jan 18, 2023
2 parents 4054c5f + 1bff469 commit 2cb346a
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions src/Forms/Controls/CurrencyInput.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ class CurrencyInput extends TextInput
public static $defaultCurrency = self::CURRENCY_CZK;
public static $defaultDataAttributeName = 'data-currency-input';

protected ?int $decimalPlaces = null;

public static $symbols = [
self::CURRENCY_CZK => '',
self::CURRENCY_EUR => '',
Expand Down Expand Up @@ -86,6 +88,10 @@ public function getFormat()
{
$options = static::$formats[$this->getOption('language')] ?? static::$formats[static::$defaultLanguage];

if ($this->decimalPlaces) {
$options['decimalPlaces'] = $this->decimalPlaces;
}

switch ($options['currencyExpression']) {
case 'symbol':
$options['currencySymbol'] = static::$symbols[$this->getOption('currency') ?? static::$defaultCurrency];
Expand Down Expand Up @@ -137,6 +143,14 @@ public function setValue($value)
return $this;
}


public function setDecimalPlaces(int $decimalPlaces): self
{
$this->decimalPlaces = $decimalPlaces;
return $this;
}


public function parseAmount($amount)
{
$options = $this->getFormat();
Expand Down

0 comments on commit 2cb346a

Please sign in to comment.