Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
Y
yii2
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PSDI Army
yii2
Commits
dfc4de87
Commit
dfc4de87
authored
Oct 03, 2014
by
Carsten Brandt
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ensure integer is formatted without fraction digits
fixes #5179
parent
df9a0f08
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
44 additions
and
1 deletion
+44
-1
Formatter.php
framework/i18n/Formatter.php
+1
-0
FormatterTest.php
tests/unit/framework/i18n/FormatterTest.php
+43
-1
No files found.
framework/i18n/Formatter.php
View file @
dfc4de87
...
...
@@ -727,6 +727,7 @@ class Formatter extends Component
$value
=
$this
->
normalizeNumericValue
(
$value
);
if
(
$this
->
_intlLoaded
)
{
$f
=
$this
->
createNumberFormatter
(
NumberFormatter
::
DECIMAL
,
null
,
$options
,
$textOptions
);
$f
->
setAttribute
(
NumberFormatter
::
FRACTION_DIGITS
,
0
);
return
$f
->
format
(
$value
,
NumberFormatter
::
TYPE_INT64
);
}
else
{
return
number_format
((
int
)
$value
,
0
,
$this
->
decimalSeparator
,
$this
->
thousandSeparator
);
...
...
tests/unit/framework/i18n/FormatterTest.php
View file @
dfc4de87
...
...
@@ -2,7 +2,9 @@
namespace
yiiunit\framework\i18n
;
use
NumberFormatter
;
use
yii\i18n\Formatter
;
use
Yii
;
use
yiiunit\TestCase
;
use
DateTime
;
use
DateInterval
;
...
...
@@ -575,9 +577,49 @@ class FormatterTest extends TestCase
// number format
/**
* 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
[];
}
public
function
testIntlAsInteger
()
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
();
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment