95dceb2089c19bdc875a03c1274dcbdca07d7eb1
2 * Provides helper functions for Number handling.
4 * @author Tim Duesterhus
5 * @copyright 2001-2022 WoltLab GmbH
6 * @license GNU Lesser General Public License <http://opensource.org/licenses/lgpl-license.php>
7 * @deprecated 6.0 All functionality in this module is deprecated.
9 define(["require", "exports"], function (require
, exports
) {
11 Object
.defineProperty(exports
, "__esModule", { value
: true });
12 exports
.round
= void 0;
14 * @deprecated 6.0 Use `Number.toLocaleString()` or `Number.toFixed()` as appropriate.
16 function round(value
, exp
) {
17 // If the exp is undefined or zero...
18 if (typeof exp
=== "undefined" || +exp
=== 0) {
19 return Math
.round(value
);
23 // If the value is not a number or the exp is not an integer...
24 if (isNaN(value
) || !(typeof exp
=== "number" && exp
% 1 === 0)) {
28 let tmp
= value
.toString().split("e");
29 let exponent
= tmp
[1] ? +tmp
[1] - exp
: -exp
;
30 value
= Math
.round(+`${tmp[0]}e${exponent}`);
32 tmp
= value
.toString().split("e");
33 exponent
= tmp
[1] ? +tmp
[1] + exp
: exp
;
34 return +`${tmp[0]}e${exponent}`;
36 exports
.round
= round
;