Skip to content

Commit 3ce0b7e

Browse files
committed
fix: adjust price formatting to account for meme coins
1 parent 13fa855 commit 3ce0b7e

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

src/utils.ts

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,6 @@ import chalk from 'chalk'
33
const ERROR = chalk.bold.red
44
const SUCCESS = chalk.bold.green
55

6-
const formatter = new Intl.NumberFormat('en-US', {
7-
style: 'currency',
8-
currency: 'USD'
9-
})
10-
116
export const logError = (message: string) => {
127
console.error(ERROR(message))
138
process.exit(1)
@@ -18,7 +13,16 @@ export const logSuccess = (message: string) => {
1813
}
1914

2015
export const format = (price: number) => {
21-
return formatter.format(price)
16+
const decimalPart = price.toString().split('.')[1]
17+
// If the decimal part starts with 0000, it's likely a meme coin
18+
// and we want to show more decimal places to avoid showing 0.00
19+
const isMemeCoin = decimalPart && decimalPart.slice(0, 4) === '0000'
20+
21+
return new Intl.NumberFormat('en-US', {
22+
style: 'currency',
23+
currency: 'USD',
24+
maximumFractionDigits: isMemeCoin ? 10 : 2
25+
}).format(price)
2226
}
2327

2428
export const formatFileName = (coinName: string, fileExt: string): string => {

0 commit comments

Comments
 (0)