Skip to content
This repository has been archived by the owner on Sep 24, 2024. It is now read-only.

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 22e5f97
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 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
11 changes: 8 additions & 3 deletions src/CFPropertyList/CFNumber.php
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,7 @@
namespace CFPropertyList;

use \DOMDocument;
use \Iterator;
use \ArrayAccess;
use \NumberFormatter;

/**
* Number Type of CFPropertyList
Expand All @@ -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;
}

/**
Expand Down

0 comments on commit 22e5f97

Please sign in to comment.