2 * Provides helper functions for Number handling.
4 * @author Tim Duesterhus
5 * @copyright 2001-2017 WoltLab GmbH
6 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
7 * @module WoltLabSuite/Core/NumberUtil
9 define([], function() {
13 * @exports WoltLabSuite/Core/NumberUtil
17 * Decimal adjustment of a number.
19 * @see https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round
20 * @param {Number} value The number.
21 * @param {Integer} exp The exponent (the 10 logarithm of the adjustment base).
22 * @returns {Number} The adjusted value.
24 round: function (value
, exp
) {
25 // If the exp is undefined or zero...
26 if (typeof exp
=== 'undefined' || +exp
=== 0) {
27 return Math
.round(value
);
32 // If the value is not a number or the exp is not an integer...
33 if (isNaN(value
) || !(typeof exp
=== 'number' && exp
% 1 === 0)) {
38 value
= value
.toString().split('e');
39 value
= Math
.round(+(value
[0] + 'e' + (value
[1] ? (+value
[1] - exp
) : -exp
)));
42 value
= value
.toString().split('e');
43 return +(value
[0] + 'e' + (value
[1] ? (+value
[1] + exp
) : exp
));