2024-04-16 12:20:29 +02:00
|
|
|
import { formatCurrency } from '@coingecko/cryptoformat'
|
|
|
|
|
|
|
|
export function formatCrypto(price: number, currency: string, locale: string) {
|
|
|
|
return formatCurrency(price, currency, locale, false, {
|
|
|
|
decimalPlaces: 3,
|
2024-08-06 23:01:43 +02:00
|
|
|
significantFigures: 5
|
2024-04-16 12:20:29 +02:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
export function formatFiat(price: number, currency: string, locale: string) {
|
|
|
|
let formattedPrice = formatCurrency(price, currency, locale, false, {
|
2024-09-21 19:22:45 +02:00
|
|
|
decimalPlaces: price < 1 ? 6 : 2,
|
2024-04-16 12:20:29 +02:00
|
|
|
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
|
|
|
|
}
|