1 | import root from './_root.js';
|
2 | import toInteger from './toInteger.js';
|
3 | import toNumber from './toNumber.js';
|
4 | import toString from './toString.js';
|
5 |
|
6 |
|
7 | var nativeIsFinite = root.isFinite,
|
8 | nativeMin = Math.min;
|
9 |
|
10 |
|
11 |
|
12 |
|
13 |
|
14 |
|
15 |
|
16 |
|
17 | function createRound(methodName) {
|
18 | var func = Math[methodName];
|
19 | return function(number, precision) {
|
20 | number = toNumber(number);
|
21 | precision = precision == null ? 0 : nativeMin(toInteger(precision), 292);
|
22 | if (precision && nativeIsFinite(number)) {
|
23 |
|
24 |
|
25 | var pair = (toString(number) + 'e').split('e'),
|
26 | value = func(pair[0] + 'e' + (+pair[1] + precision));
|
27 |
|
28 | pair = (toString(value) + 'e').split('e');
|
29 | return +(pair[0] + 'e' + (+pair[1] - precision));
|
30 | }
|
31 | return func(number);
|
32 | };
|
33 | }
|
34 |
|
35 | export default createRound;
|