Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
N
number_abbreviation
Manage
Activity
Members
Labels
Plan
Wiki
Custom issue tracker
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Model registry
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
project
number_abbreviation
Commits
cef3edbf
Commit
cef3edbf
authored
1 year ago
by
Anas Mawlawi
Committed by
Anas Mawlawi
1 year ago
Browse files
Options
Downloads
Patches
Plain Diff
Issue
#3364279
by Anas_maw: Coding standards
parent
c8ad2946
No related branches found
Branches containing commit
Tags
1.0.0-alpha19
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
number_abbreviation.services.yml
+2
-2
2 additions, 2 deletions
number_abbreviation.services.yml
src/NumberAbbreviation.php
+15
-12
15 additions, 12 deletions
src/NumberAbbreviation.php
src/Twig/TwigExtension.php
+3
-3
3 additions, 3 deletions
src/Twig/TwigExtension.php
with
20 additions
and
17 deletions
number_abbreviation.services.yml
+
2
−
2
View file @
cef3edbf
...
...
@@ -2,10 +2,10 @@ services:
number_abbreviation.abbreviate
:
class
:
Drupal\number_abbreviation\NumberAbbreviation
tags
:
-
{
name
:
tag_name
}
-
{
name
:
tag_name
}
value.twig_extension
:
class
:
Drupal\number_abbreviation\Twig\TwigExtension
arguments
:
[
'
@number_abbreviation.abbreviate
'
]
arguments
:
[
"
@number_abbreviation.abbreviate
"
]
tags
:
-
{
name
:
twig.extension
}
This diff is collapsed.
Click to expand it.
src/NumberAbbreviation.php
+
15
−
12
View file @
cef3edbf
...
...
@@ -16,24 +16,27 @@ class NumberAbbreviation implements NumberAbbreviationInterface {
* @return string
* the abbreviated number.
*/
public
function
abbreviate
(
$number
,
$decimal
=
1
){
// Make sure the number is in correct format
public
function
abbreviate
(
$number
,
$decimal
=
1
)
{
// Make sure the number is in correct format
.
$number
=
(
$number
==
(
int
)
$number
)
?
(
int
)
$number
:
(
float
)
$number
;
if
(
$number
<
1000
)
{
// Anything less than a thousand
$number
=
number_format
(
$number
,
$decimal
);
}
else
if
(
$number
<
1000000
)
{
// Anything less than a million
$number
=
number_format
(
$number
/
1000
,
$decimal
)
.
'K'
;
}
else
if
(
$number
<
1000000000
)
{
// Anything less than a billion
// Anything less than a thousand.
$number
=
number_format
(
$number
,
$decimal
);
}
elseif
(
$number
<
1000000
)
{
// Anything less than a million.
$number
=
number_format
(
$number
/
1000
,
$decimal
)
.
'K'
;
}
elseif
(
$number
<
1000000000
)
{
// Anything less than a billion.
$number
=
number_format
(
$number
/
1000000
,
$decimal
)
.
'M'
;
}
else
{
// At least a billion
}
else
{
// At least a billion.
$number
=
number_format
(
$number
/
1000000000
,
$decimal
)
.
'B'
;
}
return
str_replace
(
'.00'
,
''
,
$number
);
}
...
...
This diff is collapsed.
Click to expand it.
src/Twig/TwigExtension.php
+
3
−
3
View file @
cef3edbf
...
...
@@ -8,7 +8,7 @@ use Drupal\number_abbreviation\NumberAbbreviationInterface;
* Defines a controller for TwigExtension.
*/
class
TwigExtension
extends
\Twig_Extension
{
/**
* The number abbreviation service.
*
...
...
@@ -28,7 +28,7 @@ class TwigExtension extends \Twig_Extension {
*/
public
function
getFilters
()
{
return
[
new
\Twig_SimpleFilter
(
'number_abbreviate'
,
[
$this
,
'numberAbbreviate'
]),
new
\Twig_SimpleFilter
(
'number_abbreviate'
,
[
$this
,
'numberAbbreviate'
]),
];
}
...
...
@@ -37,7 +37,7 @@ class TwigExtension extends \Twig_Extension {
*/
public
function
getFunctions
()
{
return
[
new
\Twig_SimpleFunction
(
'number_abbreviate'
,
[
$this
,
'numberAbbreviate'
],[]),
new
\Twig_SimpleFunction
(
'number_abbreviate'
,
[
$this
,
'numberAbbreviate'
],
[]),
];
}
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment