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