Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Use ordinal constant in ordinal method, accept type options verbatim …
…in formatter method
  • Loading branch information
bcrowe committed Sep 4, 2015
1 parent 87263dc commit afe56ab
Showing 1 changed file with 7 additions and 8 deletions.
15 changes: 7 additions & 8 deletions src/I18n/Number.php
Expand Up @@ -253,7 +253,7 @@ public static function defaultCurrency($currency = null)
*
* - `locale` - The locale name to use for formatting the number, e.g. fr_FR
* - `type` - The formatter type to construct, set it to `currency` if you need to format
* numbers representing money or 'ordinal' for the ordinal numbers.
* numbers representing money or a NumberFormatter constant.
* - `places` - Number of decimal places to use. e.g. 2
* - `precision` - Maximum Number of decimal places to use, e.g. 2
* - `pattern` - An ICU number pattern to use for formatting the number. e.g #,###.00
Expand All @@ -272,12 +272,11 @@ public static function formatter($options = [])
}

$type = NumberFormatter::DECIMAL;
if (!empty($options['type']) && $options['type'] === 'currency') {
$type = NumberFormatter::CURRENCY;
}

if (!empty($options['type']) && $options['type'] === 'ordinal') {
$type = NumberFormatter::ORDINAL;
if (!empty($options['type'])) {
$type = $options['type'];
if ($options['type'] === 'currency') {
$type = NumberFormatter::CURRENCY;
}
}

if (!isset(static::$_formatters[$locale][$type])) {
Expand Down Expand Up @@ -326,6 +325,6 @@ public static function formatter($options = [])
*/
public static function ordinal($value, array $options = [])
{
return static::formatter(['type' => 'ordinal'] + $options)->format($value);
return static::formatter(['type' => NumberFormatter::ORDINAL] + $options)->format($value);
}
}

0 comments on commit afe56ab

Please sign in to comment.