summaryrefslogtreecommitdiff
path: root/spec/javascripts/lib
diff options
context:
space:
mode:
authorKushal Pandya <kushal@gitlab.com>2018-07-23 15:09:10 +0530
committerKushal Pandya <kushal@gitlab.com>2018-07-24 12:58:08 +0530
commitb48788149485d376776c6ad7c92ef2e4f2e49930 (patch)
tree442ea43ca85cd38d651ccafbc8d72f89e8eb2249 /spec/javascripts/lib
parent906eb7dc1c2a2ab1332c784e133153485b950807 (diff)
downloadgitlab-ce-b48788149485d376776c6ad7c92ef2e4f2e49930.tar.gz
Add `roundOffFloat` helper method
Diffstat (limited to 'spec/javascripts/lib')
-rw-r--r--spec/javascripts/lib/utils/common_utils_spec.js19
1 files changed, 19 insertions, 0 deletions
diff --git a/spec/javascripts/lib/utils/common_utils_spec.js b/spec/javascripts/lib/utils/common_utils_spec.js
index 41ff59949e5..71b26a315af 100644
--- a/spec/javascripts/lib/utils/common_utils_spec.js
+++ b/spec/javascripts/lib/utils/common_utils_spec.js
@@ -627,4 +627,23 @@ describe('common_utils', () => {
});
});
});
+
+ describe('roundOffFloat', () => {
+ it('Rounds off decimal places of a float number with provided precision', () => {
+ expect(commonUtils.roundOffFloat(3.141592, 3)).toBe(3.142);
+ });
+
+ it('Rounds off a float number to a whole number when provided precision is zero', () => {
+ expect(commonUtils.roundOffFloat(3.141592, 0)).toBe(3);
+ expect(commonUtils.roundOffFloat(3.5, 0)).toBe(4);
+ });
+
+ it('Rounds off float number to nearest 0, 10, 100, 1000 and so on when provided precision is below 0', () => {
+ expect(commonUtils.roundOffFloat(34567.14159, -1)).toBe(34570);
+ expect(commonUtils.roundOffFloat(34567.14159, -2)).toBe(34600);
+ expect(commonUtils.roundOffFloat(34567.14159, -3)).toBe(35000);
+ expect(commonUtils.roundOffFloat(34567.14159, -4)).toBe(30000);
+ expect(commonUtils.roundOffFloat(34567.14159, -5)).toBe(0);
+ });
+ });
});