summaryrefslogtreecommitdiff
path: root/app/assets/javascripts/lib
diff options
context:
space:
mode:
authorPhil Hughes <me@iamphill.com>2018-07-24 11:33:09 +0000
committerPhil Hughes <me@iamphill.com>2018-07-24 11:33:09 +0000
commit7dabb48e9b186db19359b6e0b9884ece3620a782 (patch)
treeaedf0dccc09437f8d79fb3487b2ce467172b069a /app/assets/javascripts/lib
parent1c24eafb4106dc7890ef74093a59009e94baa705 (diff)
parent32dffd465b0021ee4cbed7645ff40d36328c5130 (diff)
downloadgitlab-ce-7dabb48e9b186db19359b6e0b9884ece3620a782.tar.gz
Merge branch 'kp-stacked-progress-bar-decimal-places' into 'master'
Show decimal place up to single digit in Stacked Progress Bar Closes gitlab-ee#6028 See merge request gitlab-org/gitlab-ce!20776
Diffstat (limited to 'app/assets/javascripts/lib')
-rw-r--r--app/assets/javascripts/lib/utils/common_utils.js20
1 files changed, 20 insertions, 0 deletions
diff --git a/app/assets/javascripts/lib/utils/common_utils.js b/app/assets/javascripts/lib/utils/common_utils.js
index 6b7550efff8..2f3dd6f6cbc 100644
--- a/app/assets/javascripts/lib/utils/common_utils.js
+++ b/app/assets/javascripts/lib/utils/common_utils.js
@@ -541,6 +541,26 @@ export const addSelectOnFocusBehaviour = (selector = '.js-select-on-focus') => {
});
};
+/**
+ * Method to round of values with decimal places
+ * with provided precision.
+ *
+ * Taken from https://stackoverflow.com/a/7343013/414749
+ *
+ * Eg; roundOffFloat(3.141592, 3) = 3.142
+ *
+ * Refer to spec/javascripts/lib/utils/common_utils_spec.js for
+ * more supported examples.
+ *
+ * @param {Float} number
+ * @param {Number} precision
+ */
+export const roundOffFloat = (number, precision = 0) => {
+ // eslint-disable-next-line no-restricted-properties
+ const multiplier = Math.pow(10, precision);
+ return Math.round(number * multiplier) / multiplier;
+};
+
window.gl = window.gl || {};
window.gl.utils = {
...(window.gl.utils || {}),