Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions src/Currency.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,15 @@ public function format($value, $code = null)
$format = $this->getCurrencyProp($code, 'format');

// Value Regex
$valRegex = '/([0-9].*|)[0-9]/';
$valRegex = '/(?:[0-9].*|)[0-9]/';

// Match value format string
preg_match($valRegex, $format, $valFormat);

$valFormat = $valFormat[0];

// Match decimal and thousand separators
preg_match_all('/[\s\',.!]/', $format, $separators);
preg_match_all('/[\s\',.!]/', $valFormat, $separators);

if ($thousand = array_get($separators, '0.0', null)) {
if ($thousand == '!') {
Expand All @@ -130,19 +135,14 @@ public function format($value, $code = null)

$decimal = array_get($separators, '0.1', null);

// Match format for decimals count
preg_match($valRegex, $format, $valFormat);

$valFormat = array_get($valFormat, 0, 0);

// Count decimals length
$decimals = $decimal ? strlen(substr(strrchr($valFormat, $decimal), 1)) : 0;

// Format the value
$value = number_format($value, $decimals, $decimal, $thousand);

// Return the formatted measurement
return preg_replace($valRegex, $value, $format);
return str_replace($valFormat, $value, $format);
}

/**
Expand Down