(micros: number | string)
| 34 | } |
| 35 | |
| 36 | export function formatCostMicros(micros: number | string): string { |
| 37 | const microsValue = Number(micros); |
| 38 | if (!Number.isFinite(microsValue)) { |
| 39 | return "$0.00"; |
| 40 | } |
| 41 | |
| 42 | const dollars = Math.abs(microsValue) / MICROS_PER_DOLLAR; |
| 43 | const rounded4 = Number(dollars.toFixed(4)); |
| 44 | if (rounded4 > 0 && rounded4 < 0.01) { |
| 45 | if (microsValue < 0) { |
| 46 | return `-$${dollars.toFixed(4)}`; |
| 47 | } |
| 48 | |
| 49 | return usdSubCentCurrencyFormatter.format(dollars); |
| 50 | } |
| 51 | |
| 52 | return usdCurrencyFormatter.format(microsToDollars(microsValue)); |
| 53 | } |
no test coverage detected