safe-math-ops 0.0.8 → 0.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +4 -0
- package/dist/index.d.ts +3 -1
- package/dist/index.js +8 -1
- package/dist/libs/format.d.ts +5 -0
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -13,4 +13,8 @@ console.log(safeMath.substract([9.99, 8]));
|
|
|
13
13
|
|
|
14
14
|
// Expected output: 1.9900000000000002
|
|
15
15
|
console.log(9.99 - 8);
|
|
16
|
+
|
|
17
|
+
// Alternatively, you can use that fixed precision point function that prevent weird decimals from appearing too.
|
|
18
|
+
// Expected output: 1.99
|
|
19
|
+
console.log(safeMath.format(9.99 - 8));
|
|
16
20
|
```
|
package/dist/index.d.ts
CHANGED
|
@@ -5,7 +5,8 @@ import getPow from "./libs/getPow";
|
|
|
5
5
|
import multiply from "./libs/multiply";
|
|
6
6
|
import replaceByInt from "./libs/replaceByInt";
|
|
7
7
|
import subtract from "./libs/subtract";
|
|
8
|
-
|
|
8
|
+
import format from "./libs/format";
|
|
9
|
+
export { add, subtract, multiply, divide, calcHighestDecimalPoint, calcDecimals, getPow, replaceByInt, format, };
|
|
9
10
|
declare const _default: {
|
|
10
11
|
add: typeof add;
|
|
11
12
|
subtract: typeof subtract;
|
|
@@ -15,5 +16,6 @@ declare const _default: {
|
|
|
15
16
|
calcDecimals: typeof calcDecimals;
|
|
16
17
|
getPow: typeof getPow;
|
|
17
18
|
replaceByInt: typeof replaceByInt;
|
|
19
|
+
format: typeof format;
|
|
18
20
|
};
|
|
19
21
|
export default _default;
|
package/dist/index.js
CHANGED
|
@@ -65,6 +65,11 @@ function subtract(numbers) {
|
|
|
65
65
|
}) / multiplier;
|
|
66
66
|
}
|
|
67
67
|
|
|
68
|
+
// src/libs/format.ts
|
|
69
|
+
function format(number, precision = 15) {
|
|
70
|
+
return Math.round(number * 10 ** precision) / 10 ** precision;
|
|
71
|
+
}
|
|
72
|
+
|
|
68
73
|
// src/index.ts
|
|
69
74
|
var src_default = {
|
|
70
75
|
add,
|
|
@@ -74,13 +79,15 @@ var src_default = {
|
|
|
74
79
|
calcHighestDecimalPoint,
|
|
75
80
|
calcDecimals,
|
|
76
81
|
getPow,
|
|
77
|
-
replaceByInt
|
|
82
|
+
replaceByInt,
|
|
83
|
+
format
|
|
78
84
|
};
|
|
79
85
|
export {
|
|
80
86
|
subtract,
|
|
81
87
|
replaceByInt,
|
|
82
88
|
multiply,
|
|
83
89
|
getPow,
|
|
90
|
+
format,
|
|
84
91
|
divide,
|
|
85
92
|
src_default as default,
|
|
86
93
|
calcHighestDecimalPoint,
|