-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex.js
37 lines (34 loc) · 929 Bytes
/
index.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
// Generated by CoffeeScript 1.7.1
(function() {
var round, round_to_human;
round = function(x, m) {
var q, y;
y = x / m;
q = Math.round(y);
return q * m;
};
module.exports = round_to_human = function(n, options) {
var exponent, len;
if (options == null) {
options = {};
}
options.threshold || (options.threshold = 10);
options.multiple || (options.multiple = 10);
options.significant || (options.significant = 2);
if (options.upwards == null) {
options.upwards = true;
}
n = Math.round(n);
if (n <= options.threshold) {
return n;
}
exponent = n.toString().length - options.significant - 1;
len = Math.pow(10, exponent) * options.multiple;
len = Math.max(options.multiple, len);
if (options.upwards && n % len) {
return round(n + len / 2 - 0.1, len);
} else {
return round(n, len);
}
};
}).call(this);