note 105463 added to numberformatter.create
| From: | daniel dot rhodes at warpasylum dot co dot uk | Date: | Fri, 19 Aug 2011 15:43:05 +0000 |
| Subject: | note 105463 added to numberformatter.create | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-182593@lists.php.net to get a copy of this message | ||
It should be noted that the locale string passed into NumberFormatter's constructor
doesn't play with UCA keywords quite as readily as, say, the Collator and IntlDateFormatter
classes' constructors.
According to the Unicode spec (http://www.unicode.org/reports/tr35), I should be able to specify a
locale of "ja_JP@numbers=jpanfin" which, for spellout mode, should give me Japanese
financial (ie. anti-forgery) numerals. When passed into NumberFormatter's constructor,
"ja_JP@numbers=jpanfin" doesn't work.
However, when I look at a dump of NumberFormatter::getPattern() for the ja_JP locale, I see that the
financial numerals *are* in there (as %financial). Here's how we wrangle them out of the
NumberFormatter:
<?php
$number = 1234567890;
$formatter = new NumberFormatter('ja_JP', NumberFormatter::SPELLOUT);
$formatter->setTextAttribute(NumberFormatter::DEFAULT_RULESET, "%financial");
echo $formatter->format($number);
//above gives
[æ¾å¼ååååç¾ä¼æ¾å
è¬ä¸åå
«ç¾ä¹æ¾]
(as opposed to
[åäºåä¸ååç¾äºåå
ä¸ä¸åå
«ç¾ä¹å])
- bingo!
?>
----
Server IP: 109.169.40.147
Probable Submitter: 109.145.233.176
----
Manual Page -- http://www.php.net/manual/en/numberformatter.create.php
Edit -- https://master.php.net/note/edit/105463
Del: integrated -- https://master.php.net/note/delete/105463/integrated
Del: useless -- https://master.php.net/note/delete/105463/useless
Del: bad code -- https://master.php.net/note/delete/105463/bad+code
Del: spam -- https://master.php.net/note/delete/105463/spam
Del: non-english -- https://master.php.net/note/delete/105463/non-english
Del: in docs -- https://master.php.net/note/delete/105463/in+docs
Del: other reasons-- https://master.php.net/note/delete/105463
Reject -- https://master.php.net/note/reject/105463
Search -- https://master.php.net/manage/user-notes.php