(value: number)
| 1 | import type { PaddleProductLineItem } from '../graphql/paddle'; |
| 2 | |
| 3 | export function largeNumberFormat(value: number): string | null { |
| 4 | if (typeof value !== 'number') { |
| 5 | return null; |
| 6 | } |
| 7 | const suffixes = ['', 'K', 'M', 'B', 'T']; |
| 8 | let suffixNum = 0; |
| 9 | while ( |
| 10 | Math.abs(value) >= 1000 ** (suffixNum + 1) && |
| 11 | suffixNum < suffixes.length - 1 |
| 12 | ) { |
| 13 | suffixNum += 1; |
| 14 | } |
| 15 | if (suffixNum === 0) { |
| 16 | return value.toString(); |
| 17 | } |
| 18 | const unit = 1000 ** suffixNum; |
| 19 | const step = Math.abs(value) < 10 * unit ? unit / 10 : unit; |
| 20 | return `${(Math.trunc(value / step) * step) / unit}${suffixes[suffixNum]}`; |
| 21 | } |
| 22 | |
| 23 | export const getRandom4Digits = (leftPad?: string): string => { |
| 24 | const random = Math.floor(1000 + Math.random() * 9000); |
no outgoing calls
no test coverage detected