2022-10-25 21:35:32 +00:00
|
|
|
export const abbrNum = n => {
|
2022-02-17 17:23:43 +00:00
|
|
|
if (n < 1e4) return n
|
|
|
|
if (n >= 1e4 && n < 1e6) return +(n / 1e3).toFixed(1) + 'k'
|
|
|
|
if (n >= 1e6 && n < 1e9) return +(n / 1e6).toFixed(1) + 'm'
|
|
|
|
if (n >= 1e9 && n < 1e12) return +(n / 1e9).toFixed(1) + 'b'
|
|
|
|
if (n >= 1e12) return +(n / 1e12).toFixed(1) + 't'
|
|
|
|
}
|
2022-07-30 13:25:46 +00:00
|
|
|
|
|
|
|
export const fixedDecimal = (n, f) => {
|
|
|
|
return Number.parseFloat(n).toFixed(f)
|
|
|
|
}
|
2022-11-15 20:51:55 +00:00
|
|
|
|
|
|
|
export const msatsToSats = msats => {
|
|
|
|
if (msats === null || msats === undefined) {
|
|
|
|
return null
|
|
|
|
}
|
|
|
|
return Number(BigInt(msats) / 1000n)
|
|
|
|
}
|
2022-12-19 22:27:52 +00:00
|
|
|
|
|
|
|
export const msatsToSatsDecimal = msats => {
|
|
|
|
if (msats === null || msats === undefined) {
|
|
|
|
return null
|
|
|
|
}
|
2023-07-27 00:18:42 +00:00
|
|
|
return fixedDecimal(Number(msats) / 1000.0, 3)
|
2022-12-19 22:27:52 +00:00
|
|
|
}
|