Skip to content
This repository was archived by the owner on Feb 17, 2025. It is now read-only.

Commit 03cdae4

Browse files
committed
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 <tbugier@teclib.com>
1 parent 2b9b667 commit 03cdae4

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

composer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
"require": {
99
"php": "^7.4 || ^8.0",
1010
"ext-dom": "*",
11-
"ext-libxml": "*"
11+
"ext-libxml": "*",
12+
"ext-intl": "*"
1213
},
1314
"authors": [
1415
{

src/CFPropertyList/CFNumber.php

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,13 @@ public function toXML(DOMDocument $doc, $nodeName = "")
6868
$this->value = intval($this->value);
6969
$ret = 'integer';
7070
}
71-
return parent::toXML($doc, $ret);
71+
$formatter = new \NumberFormatter('en_US', \NumberFormatter::DECIMAL);
72+
$formatter->setAttribute(\NumberFormatter::MAX_FRACTION_DIGITS, 10);
73+
$formatter->setAttribute(\NumberFormatter::GROUPING_USED, false);
74+
$text = $doc->createTextNode($formatter->format($this->value));
75+
$node = $doc->createElement($ret);
76+
$node->appendChild($text);
77+
return $node;
7278
}
7379

7480
/**

0 commit comments

Comments
 (0)