mirror of
https://github.com/yiisoft/yii2.git
synced 2025-11-25 19:20:29 +08:00
@@ -727,6 +727,7 @@ class Formatter extends Component
|
|||||||
$value = $this->normalizeNumericValue($value);
|
$value = $this->normalizeNumericValue($value);
|
||||||
if ($this->_intlLoaded) {
|
if ($this->_intlLoaded) {
|
||||||
$f = $this->createNumberFormatter(NumberFormatter::DECIMAL, null, $options, $textOptions);
|
$f = $this->createNumberFormatter(NumberFormatter::DECIMAL, null, $options, $textOptions);
|
||||||
|
$f->setAttribute(NumberFormatter::FRACTION_DIGITS, 0);
|
||||||
return $f->format($value, NumberFormatter::TYPE_INT64);
|
return $f->format($value, NumberFormatter::TYPE_INT64);
|
||||||
} else {
|
} else {
|
||||||
return number_format((int) $value, 0, $this->decimalSeparator, $this->thousandSeparator);
|
return number_format((int) $value, 0, $this->decimalSeparator, $this->thousandSeparator);
|
||||||
|
|||||||
@@ -2,7 +2,9 @@
|
|||||||
|
|
||||||
namespace yiiunit\framework\i18n;
|
namespace yiiunit\framework\i18n;
|
||||||
|
|
||||||
|
use NumberFormatter;
|
||||||
use yii\i18n\Formatter;
|
use yii\i18n\Formatter;
|
||||||
|
use Yii;
|
||||||
use yiiunit\TestCase;
|
use yiiunit\TestCase;
|
||||||
use DateTime;
|
use DateTime;
|
||||||
use DateInterval;
|
use DateInterval;
|
||||||
@@ -575,9 +577,49 @@ class FormatterTest extends TestCase
|
|||||||
|
|
||||||
// number format
|
// number format
|
||||||
|
|
||||||
|
/**
|
||||||
public function testIntlAsInteger()
|
* Provides some configuration that should not affect Integer formatter
|
||||||
|
*/
|
||||||
|
public function differentConfigProvider()
|
||||||
{
|
{
|
||||||
|
// make this test not break when intl is not installed
|
||||||
|
if (!extension_loaded('intl')) {
|
||||||
|
return [];
|
||||||
|
}
|
||||||
|
|
||||||
|
return [
|
||||||
|
[[
|
||||||
|
'numberFormatterOptions' => [
|
||||||
|
NumberFormatter::MIN_FRACTION_DIGITS => 2,
|
||||||
|
],
|
||||||
|
]],
|
||||||
|
[[
|
||||||
|
'numberFormatterOptions' => [
|
||||||
|
NumberFormatter::MAX_FRACTION_DIGITS => 2,
|
||||||
|
],
|
||||||
|
]],
|
||||||
|
[[
|
||||||
|
'numberFormatterOptions' => [
|
||||||
|
NumberFormatter::FRACTION_DIGITS => 2,
|
||||||
|
],
|
||||||
|
]],
|
||||||
|
[[
|
||||||
|
'numberFormatterOptions' => [
|
||||||
|
NumberFormatter::MIN_FRACTION_DIGITS => 2,
|
||||||
|
NumberFormatter::MAX_FRACTION_DIGITS => 4,
|
||||||
|
],
|
||||||
|
]],
|
||||||
|
];
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @dataProvider differentConfigProvider
|
||||||
|
*/
|
||||||
|
public function testIntlAsInteger($config)
|
||||||
|
{
|
||||||
|
// configure formatter with different configs that should not affect integer format
|
||||||
|
Yii::configure($this->formatter, $config);
|
||||||
$this->testAsInteger();
|
$this->testAsInteger();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user