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 Jun 4, 2021
1 parent d3b5376 commit 77ca3dd
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 @@ -6,7 +6,8 @@
"homepage": "https://github.com/TECLIB/CFPropertyList",
"license": "MIT",
"require": {
"php": ">=5.6"
"php": ">=5.6",
"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 77ca3dd

Please sign in to comment.