Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
vidjil
vidjil
Commits
62eefb1d
Commit
62eefb1d
authored
Oct 18, 2017
by
Mathieu Giraud
Committed by
aurelien beliard
Oct 19, 2017
Browse files
tools.js: nice_number_digits()
See
#2731
.
parent
afb6f590
Changes
1
Show whitespace changes
Inline
Side-by-side
browser/js/tools.js
View file @
62eefb1d
...
...
@@ -313,6 +313,29 @@ function nice_floor(x)
}
}
/**
* Give a minimial number of digits to represent 'x' with at least 'sd' significant digits
* nice_number_digits(14.5, 2) -> 1
* nice_number_digits(0.145, 2) -> 2
* nice_number_digits(0.0145, 2) -> 3
**/
function
nice_number_digits
(
x
,
sd
)
{
if
(
x
<=
0
)
return
sd
try
{
var
nd
=
Math
.
floor
(
Math
.
log10
(
x
))
return
Math
.
max
(
0
,
sd
-
nd
-
1
)
}
catch
(
e
)
{
// Always return something
return
sd
}
}
/**
* Sends error to the specified database reference.
* If database is undefined, throws the specified error.
...
...
Mathieu Giraud
@magiraud
mentioned in merge request
!124 (merged)
·
Nov 21, 2017
mentioned in merge request
!124 (merged)
mentioned in merge request !124
Toggle commit list
Mathieu Giraud
@magiraud
mentioned in commit
658ff73a
·
Nov 21, 2017
mentioned in commit
658ff73a
mentioned in commit 658ff73a88709f75fd37237f1c9f60d79e1e9ac3
Toggle commit list
Write
Preview
Supports
Markdown
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