-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathit7Utils.js
More file actions
40 lines (36 loc) · 1.27 KB
/
it7Utils.js
File metadata and controls
40 lines (36 loc) · 1.27 KB
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
38
39
40
;(function(){
var it7Utils = function(){};
it7Utils.version = '1.1.0';
/**
*
* @param money
* @param [c] к-во знаков после запятой
* @param [d] разделитель десятых 10.00
* @param [t] разделитель тысяч 1'000
* @returns {string}
*/
it7Utils.formatMoney = function (money, c, d, t) {
var n = parseFloat(money);
isNaN(n) && (n = 0);
var c = isNaN(c = Math.abs(c)) ? 2 : c,
d = d == undefined ? "." : d,
t = t == undefined ? "\'" : t,
s = n < 0 ? "-" : "",
n2 = Math.abs(+n || 0).toFixed(c),
i = parseInt(n2),
is = parseInt(n2).toString(),
il = i.toString().length,
j = il > 3 ? il % 3 : 0;
var o = s;
o += (j ? is.substr(0, j) + t : "");
o += is.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + t);
o += (c ? d + n.toFixed(c).slice(0-c) : "");
return o;
};
it7Utils.formatPrice = function(price, isCent) {
isCent === undefined && (isCent = true);
var m = isCent ? price / 100 : price;
return it7Utils.formatMoney(m);
};
window.it7Utils = it7Utils;
})();