mirror of
https://github.com/kremalicious/asi-calculator.git
synced 2024-12-22 09:23:16 +01:00
23 lines
671 B
TypeScript
23 lines
671 B
TypeScript
import { formatCurrency } from '@coingecko/cryptoformat'
|
|
|
|
export function formatCrypto(price: number, currency: string, locale: string) {
|
|
return formatCurrency(price, currency, locale, false, {
|
|
decimalPlaces: 3,
|
|
significantFigures: 5
|
|
})
|
|
}
|
|
|
|
export function formatFiat(price: number, currency: string, locale: string) {
|
|
let formattedPrice = formatCurrency(price, currency, locale, false, {
|
|
decimalPlaces: price < 1 ? 6 : 2,
|
|
significantFigures: 8
|
|
})
|
|
|
|
// Add a trailing zero if only one digit after the decimal
|
|
if (formattedPrice.includes('.') && formattedPrice.split('.')[1].length < 2) {
|
|
formattedPrice += '0'
|
|
}
|
|
|
|
return formattedPrice
|
|
}
|