Complex number mask for integers containing a single dot (#1227)

This commit is contained in:
Mark Baker 2019-10-30 22:54:06 +01:00 committed by GitHub
parent 1b4098da8e
commit 617ea476c0
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 14 additions and 0 deletions

View File

@ -601,6 +601,7 @@ class NumberFormat extends Supervisor
{
$sign = ($number < 0.0);
$number = abs($number);
if ($splitOnPoint && strpos($mask, '.') !== false && strpos($number, '.') !== false) {
$numbers = explode('.', $number);
$masks = explode('.', $mask);
@ -639,6 +640,9 @@ class NumberFormat extends Supervisor
// Scientific format
$value = sprintf('%5.2E', $value);
} elseif (preg_match('/0([^\d\.]+)0/', $format) || substr_count($format, '.') > 1) {
if ($value == (int) $value && substr_count($format, '.') === 1) {
$value *= 10 ** strlen(explode('.', $format)[1]);
}
$value = self::complexNumberFormatMask($value, $format);
} else {
$sprintf_pattern = "%0$minWidth." . strlen($right) . 'f';

View File

@ -58,6 +58,16 @@ return [
5.5555000000000003,
'0.00#',
],
[
'12 345.67',
12345.67,
'#\ ##0.00',
],
[
'1234 567.00',
1234567.00,
'#\ ##0.00',
],
[
'5.556',
5.5555000000000003,