14 $decimalCount = strlen($numbers[1]);
15 $postDecimalMasks = [];
18 $tempMask = array_pop($masks);
19 if ($tempMask !== null) {
20 $postDecimalMasks[] = $tempMask;
21 $decimalCount -= strlen($tempMask);
23 }
while ($tempMask !== null && $decimalCount > 0);
27 implode(
'.', array_reverse($postDecimalMasks)),
34 $maskingBlockCount = preg_match_all(
'/0+/',
$mask, $maskingBlocks, PREG_OFFSET_CAPTURE);
36 if ($maskingBlockCount > 1) {
37 $maskingBlocks = array_reverse($maskingBlocks[0]);
40 foreach ($maskingBlocks as $block) {
41 $size = strlen($block[0]);
42 $divisor = 10 **
$size;
45 $blockValue = sprintf(
"%0{$size}d", fmod($number, $divisor));
46 $number = floor($number / $divisor);
50 $mask = substr_replace(
$mask, $number, $offset, 0);
60 $sign = ($number < 0.0) ?
'-' :
'';
61 $number = abs($number);
63 if ($splitOnPoint && strpos(
$mask,
'.') !==
false && strpos($number,
'.') !==
false) {
64 $numbers = explode(
'.', $number);
65 $masks = explode(
'.',
$mask);
66 if (count($masks) > 2) {
67 $masks = self::mergeComplexNumberFormatMasks($numbers, $masks);
69 $integerPart = self::complexNumberFormatMask($numbers[0], $masks[0],
false);
70 $decimalPart = strrev(self::complexNumberFormatMask(strrev($numbers[1]), strrev($masks[1]),
false));
72 return "{$sign}{$integerPart}.{$decimalPart}";
75 $result = self::processComplexNumberFormatMask($number,
$mask);
77 return "{$sign}{$result}";
87 $minWidth = strlen($left) + strlen($dec) + strlen($right);
89 $value = number_format(
96 return preg_replace(self::NUMBER_REGEX, $value,
$format);
99 if (preg_match(
'/[0#]E[+-]0/i',
$format)) {
101 return sprintf(
'%5.2E', $value);
102 } elseif (preg_match(
'/0([^\d\.]+)0/',
$format) || substr_count(
$format,
'.') > 1) {
103 if ($value == (
int) $value && substr_count(
$format,
'.') === 1) {
104 $value *= 10 ** strlen(explode(
'.',
$format)[1]);
107 return self::complexNumberFormatMask($value,
$format);
110 $sprintf_pattern =
"%0$minWidth." . strlen($right) .
'f';
111 $value = sprintf($sprintf_pattern, $value);
113 return preg_replace(self::NUMBER_REGEX, $value,
$format);
131 $useThousands = preg_match(
'/(#,#|0,0)/',
$format);
142 if (preg_match(
'/(#|0)(,+)/',
$format, $matches)) {
143 $scale = 1000 ** strlen($matches[2]);
149 if (preg_match(
'/#?.*\?\/\?/',
$format,
$m)) {
150 if ($value != (
int) $value) {
157 $value = $value / $scale;
163 $n =
'/\\[[^\\]]+\\]/';
165 if (preg_match(self::NUMBER_REGEX,
$m, $matches)) {
167 $value = self::formatStraightNumericValue($value,
$format, $matches, $useThousands);
171 $value = str_replace(
'?',
'',
$format ??
'');
175 if (preg_match(
'/\[\$(.*)\]/u',
$format,
$m)) {
177 $currencyCode =
$m[1];
178 [$currencyCode] = explode(
'-', $currencyCode);
179 if ($currencyCode ==
'') {
182 $value = preg_replace(
'/\[\$([^\]]*)\]/u', $currencyCode, $value);
static getCurrencyCode()
Get the currency code.
static getThousandsSeparator()
Get the thousands separator.
static getDecimalSeparator()
Get the decimal separator.