mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-04 22:50:27 +00:00
Merge pull request #3401 from PHPOffice/NumberFormatter-Improved-Fractions
Allow use of # and 0 digit placeholders in fraction masks
This commit is contained in:
@@ -211,7 +211,10 @@ class NumberFormatter
|
||||
$useThousands = self::areThousandsRequired($format);
|
||||
$scale = self::scaleThousandsMillions($format);
|
||||
|
||||
if (preg_match('/#?.*\?\/(\?+|\d+)/', $format)) {
|
||||
if (preg_match('/[#\?0]?.*[#\?0]\/(\?+|\d+|#)/', $format)) {
|
||||
// It's a dirty hack; but replace # and 0 digit placeholders with ?
|
||||
$format = (string) preg_replace('/[#0]+\//', '?/', $format);
|
||||
$format = (string) preg_replace('/\/[#0]+/', '/?', $format);
|
||||
$value = FractionFormatter::format($value, $format);
|
||||
} else {
|
||||
// Handle the number itself
|
||||
|
||||
@@ -9,6 +9,26 @@ return [
|
||||
5.25,
|
||||
'# ???/???',
|
||||
],
|
||||
[
|
||||
'5 2/8',
|
||||
5.25,
|
||||
'# ???/8',
|
||||
],
|
||||
[
|
||||
'5 4/16',
|
||||
5.25,
|
||||
'# ???/16',
|
||||
],
|
||||
[
|
||||
'5 1/4',
|
||||
5.25,
|
||||
'# ##0/000',
|
||||
],
|
||||
[
|
||||
'5 1/4',
|
||||
5.25,
|
||||
'# ##0/###',
|
||||
],
|
||||
[
|
||||
'5 3/10',
|
||||
5.2999999999999998,
|
||||
|
||||
Reference in New Issue
Block a user