(balance: number, toUnit: string, withFormatting = false)
| 375 | * @returns {string} |
| 376 | */ |
| 377 | export function formatBalance(balance: number, toUnit: string, withFormatting = false): string { |
| 378 | if (toUnit === undefined) { |
| 379 | return balance + ' ' + loc.units[BitcoinUnit.BTC]; |
| 380 | } |
| 381 | if (toUnit === BitcoinUnit.BTC) { |
| 382 | const value = new BigNumber(balance).dividedBy(100000000).toFixed(8); |
| 383 | return removeTrailingZeros(value) + ' ' + loc.units[BitcoinUnit.BTC]; |
| 384 | } else if (toUnit === BitcoinUnit.SATS) { |
| 385 | return (withFormatting ? new Intl.NumberFormat().format(balance).toString() : String(balance)) + ' ' + loc.units[BitcoinUnit.SATS]; |
| 386 | } else { |
| 387 | console.debug('[UnitSwitch/Fiat] formatBalance to fiat', { balance, unit: toUnit, withFormatting }); |
| 388 | return satoshiToLocalCurrency(balance); |
| 389 | } |
| 390 | } |
| 391 | |
| 392 | /** |
| 393 | * |
no test coverage detected