Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
W
wallet
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
hive
wallet
Commits
9bddfd45
Commit
9bddfd45
authored
3 years ago
by
Quoc Huy Nguyen Dinh
Browse files
Options
Downloads
Patches
Plain Diff
Indentation
parent
d5dfb254
No related branches found
No related tags found
3 merge requests
!137
Closes #36
,
!133
Fix: Governance expiry warning should have proper year at all times
,
!132
Witnesses page fixes
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/app/utils/ParsersAndFormatters.js
+20
-10
20 additions, 10 deletions
src/app/utils/ParsersAndFormatters.js
with
20 additions
and
10 deletions
src/app/utils/ParsersAndFormatters.js
+
20
−
10
View file @
9bddfd45
...
...
@@ -7,8 +7,14 @@ function fractional_part_len(value) {
// FIXME this should be unit tested.. here is one bug: 501,695,.505
export
function
formatDecimal
(
value
,
decPlaces
=
2
,
truncate0s
=
true
)
{
let
decSeparator
,
fl
,
i
,
j
,
sign
,
thouSeparator
,
abs_value
;
if
(
value
===
null
||
value
===
void
0
||
isNaN
(
value
))
{
let
fl
;
if
(
value
===
null
||
// eslint-disable-next-line no-void
value
===
void
0
||
// eslint-disable-next-line no-restricted-globals
isNaN
(
value
)
)
{
return
[
'
N
'
,
'
a
'
,
'
N
'
];
}
if
(
truncate0s
)
{
...
...
@@ -16,12 +22,12 @@ export function formatDecimal(value, decPlaces = 2, truncate0s = true) {
if
(
fl
<
2
)
fl
=
2
;
if
(
fl
<
decPlaces
)
decPlaces
=
fl
;
}
decSeparator
=
'
.
'
;
thouSeparator
=
'
,
'
;
sign
=
value
<
0
?
'
-
'
:
''
;
abs_value
=
Math
.
abs
(
value
);
i
=
parseInt
(
abs_value
.
toFixed
(
decPlaces
),
10
)
+
''
;
j
=
i
.
length
;
const
decSeparator
=
'
.
'
;
const
thouSeparator
=
'
,
'
;
const
sign
=
value
<
0
?
'
-
'
:
''
;
const
abs_value
=
Math
.
abs
(
value
);
const
i
=
parseInt
(
abs_value
.
toFixed
(
decPlaces
),
10
)
+
''
;
let
j
=
i
.
length
;
j
=
i
.
length
>
3
?
j
%
3
:
0
;
const
decPart
=
decPlaces
?
decSeparator
+
...
...
@@ -60,8 +66,10 @@ export const repLog10 = (rep2) => {
rep
=
neg
?
rep
.
substring
(
1
)
:
rep
;
let
out
=
log10
(
rep
);
// eslint-disable-next-line no-restricted-globals
if
(
isNaN
(
out
))
out
=
0
;
out
=
Math
.
max
(
out
-
9
,
0
);
// @ -9, $0.50 earned is approx magnitude 1
// eslint-disable-next-line operator-assignment
out
=
(
neg
?
-
1
:
1
)
*
out
;
out
=
out
*
9
+
25
;
// 9 points per magnitude. center at 25
// base-line 0 to darken and < 0 to auto hide (grep rephide)
...
...
@@ -72,7 +80,7 @@ export const repLog10 = (rep2) => {
export
function
countDecimals
(
amount
)
{
if
(
amount
==
null
)
return
amount
;
amount
=
String
(
amount
)
.
match
(
/
[\d
\
.]
+/g
)
.
match
(
/
[\d
.
]
+/g
)
.
join
(
''
);
// just dots and digits
const
parts
=
amount
.
split
(
'
.
'
);
return
parts
.
length
>
2
...
...
@@ -94,7 +102,7 @@ export function formatLargeNumber(number, decimals) {
];
const
regexp
=
/
\.
0+$|
(\.[
0-9
]
*
[
1-9
])
0+$/
;
for
(
let
i
=
symbols
.
length
-
1
;
i
>
0
;
i
--
)
{
for
(
let
i
=
symbols
.
length
-
1
;
i
>
0
;
i
-=
1
)
{
if
(
number
>=
symbols
[
i
].
value
)
{
return
(
(
number
/
symbols
[
i
].
value
)
...
...
@@ -103,6 +111,8 @@ export function formatLargeNumber(number, decimals) {
);
}
}
return
number
;
}
// this function searches for right translation of provided error (usually from back-end)
...
...
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