From 22e5f97f4ef35bba45a779281ee798875545588d Mon Sep 17 00:00:00 2001 From: Thierry Bugier Date: Thu, 3 Jun 2021 23:59:04 +0200 Subject: [PATCH] fix(CFNumber): locale insensitive float format CFNumber must output floats with dot as decimal separator This change forces a 10 digits limit after the decimal separator Signed-off-by: Thierry Bugier --- composer.json | 3 ++- src/CFPropertyList/CFNumber.php | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index d973284..a6ecbf4 100644 --- a/composer.json +++ b/composer.json @@ -8,7 +8,8 @@ "require": { "php": "^7.4 || ^8.0", "ext-dom": "*", - "ext-libxml": "*" + "ext-libxml": "*", + "ext-intl": "*" }, "authors": [ { diff --git a/src/CFPropertyList/CFNumber.php b/src/CFPropertyList/CFNumber.php index f2b6518..2d303a5 100644 --- a/src/CFPropertyList/CFNumber.php +++ b/src/CFPropertyList/CFNumber.php @@ -45,8 +45,7 @@ namespace CFPropertyList; use \DOMDocument; -use \Iterator; -use \ArrayAccess; +use \NumberFormatter; /** * Number Type of CFPropertyList @@ -68,7 +67,13 @@ public function toXML(DOMDocument $doc, $nodeName = "") $this->value = intval($this->value); $ret = 'integer'; } - return parent::toXML($doc, $ret); + $formatter = new NumberFormatter('en_US', NumberFormatter::DECIMAL); + $formatter->setAttribute(NumberFormatter::MAX_FRACTION_DIGITS, 10); + $formatter->setAttribute(NumberFormatter::GROUPING_USED, false); + $text = $doc->createTextNode($formatter->format($this->value)); + $node = $doc->createElement($ret); + $node->appendChild($text); + return $node; } /**