-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathutils.js
32 lines (30 loc) · 953 Bytes
/
utils.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
calcPrecision = (price) => {
const totalPrecision = 8
let pricePrecision = 4
let amountPrecision = totalPrecision - pricePrecision
if (!price) return { pricePrecision: totalPrecision, amountPrecision: totalPrecision }
switch (true) {
case (price >= 50):
pricePrecision = 2
amountPrecision = totalPrecision - pricePrecision
break
case (price >= 1):
pricePrecision = 4
amountPrecision = totalPrecision - pricePrecision
break
case (price >= 0.1):
pricePrecision = 5
amountPrecision = totalPrecision - pricePrecision
break
case (price >= 0.001):
pricePrecision = 6
amountPrecision = totalPrecision - pricePrecision
break
default:
pricePrecision = 8
amountPrecision = totalPrecision - pricePrecision
break
}
return { pricePrecision, amountPrecision }
}
module.exports = { calcPrecision }