Skip to content

Commit

Permalink
Token and cost formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
m-rgba committed Dec 20, 2024
1 parent fcb51c3 commit 9c1f850
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,25 +66,16 @@ export const FORMAT_NUMBER_NO_DECIMALS = new Intl.NumberFormat('en-US', {

// Number formatting function that formats numbers in the thousands and millions with 3 sigfigs
export const formatTokenCount = (num: number): string => {
if (num < 10000) {
if (num < 1000000) {
return FORMAT_NUMBER_NO_DECIMALS.format(num);
} else if (num >= 10000 && num < 1000000) {
// Format numbers in the thousands
const thousands = (num / 1000).toFixed(1);
return parseFloat(thousands).toString() + 'k';
}
// Format numbers in the millions
const millions = (num / 1000000).toFixed(2);
return parseFloat(millions).toString() + 'm';
};

export const formatTokenCost = (cost: number): string => {
if (cost === 0) {
return '$0.00';
} else if (cost < 0.01) {
return '$<0.01';
}
return `$${cost.toFixed(2)}`;
return `$${cost.toFixed(4)}`;
};

// TODO(Josiah): this is here because sometimes the cost query is not returning all the ids I believe for unfinished calls,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -441,6 +441,8 @@ function buildCallsTableColumns(
width: 100,
minWidth: 100,
maxWidth: 100,
align: 'right',
headerAlign: 'right',
// Should probably have a custom filter here.
filterable: false,
sortable: false,
Expand All @@ -463,6 +465,8 @@ function buildCallsTableColumns(
width: 100,
minWidth: 100,
maxWidth: 100,
align: 'right',
headerAlign: 'right',
// Should probably have a custom filter here.
filterable: false,
sortable: false,
Expand Down

0 comments on commit 9c1f850

Please sign in to comment.