-
Notifications
You must be signed in to change notification settings - Fork 0
/
getAbsoluteValues
32 lines (30 loc) · 1.75 KB
/
getAbsoluteValues
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
var commonService = function($http, $q){
commonServiceFactory.sumFloats = function (a, b) {
var aDecimalsPlaces = 0; var bDecimalsPlaces = 0;
if (a.toString().indexOf('.') > -1)
aDecimalsPlaces = a.toString().split('.')[1].length;
if (b.toString().indexOf('.') > -1)
bDecimalsPlaces = b.toString().split('.')[1].length;
var multiplier = (aDecimalsPlaces > bDecimalsPlaces) ? math.pow(10, aDecimalsPlaces) : math.pow(10, bDecimalsPlaces);
return Math.round(a * multiplier + b * multiplier) / multiplier;
};
commonServiceFactory.diffFloats = function (a, b) {
var aDecimalsPlaces = 0; var bDecimalsPlaces = 0;
if (a.toString().indexOf('.') > -1)
aDecimalsPlaces = a.toString().split('.')[1].length;
if (b.toString().indexOf('.') > -1)
bDecimalsPlaces = b.toString().split('.')[1].length;
var multiplier = (aDecimalsPlaces > bDecimalsPlaces) ? math.pow(10, aDecimalsPlaces) : math.pow(10, bDecimalsPlaces);
return Math.round(a * multiplier - b * multiplier) / multiplier;
};
commonServiceFactory.mulFloats = function (a, b) {
var aDecimalsPlaces = 0; var bDecimalsPlaces = 0;
if (a.toString().indexOf('.') > -1)
aDecimalsPlaces = a.toString().split('.')[1].length;
if (b.toString().indexOf('.') > -1)
bDecimalsPlaces = b.toString().split('.')[1].length;
var multiplier = (aDecimalsPlaces > bDecimalsPlaces) ? math.pow(10, aDecimalsPlaces) : math.pow(10, bDecimalsPlaces);
return Math.round(a * b * multiplier) / multiplier;
};
return commonServiceFactory;
};