Skip to content

Commit

Permalink
fix(CFNumber): locale insensitive float format
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
btry committed Feb 8, 2023
1 parent 2b9b667 commit 03cdae4
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
"require": {
"php": "^7.4 || ^8.0",
"ext-dom": "*",
"ext-libxml": "*"
"ext-libxml": "*",
"ext-intl": "*"
},
"authors": [
{
Expand Down
8 changes: 7 additions & 1 deletion src/CFPropertyList/CFNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,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;
}

/**
Expand Down

0 comments on commit 03cdae4

Please sign in to comment.