summaryrefslogtreecommitdiff
path: root/addons/web/static/tests/core/util_tests.js
diff options
context:
space:
mode:
authorMathieu Duckerts-Antoine <dam@odoo.com>2019-02-14 16:04:18 +0000
committerMathieu Duckerts-Antoine <dam@odoo.com>2019-02-15 10:51:01 +0000
commit24b0f092b4f5ac7043430f106486fa2ab8829c21 (patch)
tree898ca1208bdbc7e7aac3909acace72bb119930ed /addons/web/static/tests/core/util_tests.js
parent03e80650c7bf40a5fdac7019a1306e5e1db6565b (diff)
[FIX] web: remove human_number limitations
The formatting of very big numbers (like 1.0045e+22) was not handled adequately by the function 'human_number' in web.utils. For those numbers, it seems more appropriate to use the scientific format. The only difference introduced here is the following. Beyond a magnitude of e+21, we represent the numbers by themselves but we keep the number of decimals provided as parameter (or zero by default) and we remove useless zero decimals like in the other cases. For instance, 1.0045e+22 is replaced by 1e+22 instead of 1.00e+22 if ask 2 decimals of precision (and by 1.005e+22 for 3 decimals). We have also fixed a small bug occuring in the previous version of the function: the symbol 'E' was never used. So by the past the above number would have be represented as 10045000P and, even worse, 1.01e+45 by 1.012e+28P. closes odoo/odoo#31140
Diffstat (limited to 'addons/web/static/tests/core/util_tests.js')
-rw-r--r--addons/web/static/tests/core/util_tests.js22
1 files changed, 21 insertions, 1 deletions
diff --git a/addons/web/static/tests/core/util_tests.js b/addons/web/static/tests/core/util_tests.js
index c7158083dcb..f81dea7ce4e 100644
--- a/addons/web/static/tests/core/util_tests.js
+++ b/addons/web/static/tests/core/util_tests.js
@@ -55,6 +55,26 @@ QUnit.module('core', {}, function () {
assert.strictEqual(is_bin_size('64.2 Кб'), true);
});
+ QUnit.test('human_number', function (assert) {
+ assert.expect(13);
+
+ var human_number = utils.human_number;
+
+ assert.strictEqual(human_number(1020, 2, 1), '1.02k');
+ assert.strictEqual(human_number(1020000, 2, 2), '1020k');
+ assert.strictEqual(human_number(10200000, 2, 2), '10.2M');
+ assert.strictEqual(human_number(1020, 2, 1), '1.02k');
+ assert.strictEqual(human_number(1002, 2, 1), '1k');
+ assert.strictEqual(human_number(101, 2, 1), '101');
+ assert.strictEqual(human_number(64.2, 2, 1), '64');
+ assert.strictEqual(human_number(1e+18), '1E');
+ assert.strictEqual(human_number(1e+21, 2, 1), '1e+21');
+ assert.strictEqual(human_number(1.0045e+22, 2, 1), '1e+22');
+ assert.strictEqual(human_number(1.0045e+22, 3, 1), '1.005e+22');
+ assert.strictEqual(human_number(1.012e+43, 2, 1), '1.01e+43');
+ assert.strictEqual(human_number(1.012e+43, 2, 2), '1.01e+43');
+ });
+
});
-}); \ No newline at end of file
+});