Skip to content

Commit

Permalink
Merge pull request #1617 from bancorprotocol/issue-#1616
Browse files Browse the repository at this point in the history
Use e+ notation for very large number
  • Loading branch information
GrandSchtroumpf authored Dec 19, 2024
2 parents 50e063b + 1a8924c commit 02ab4eb
Show file tree
Hide file tree
Showing 16 changed files with 18 additions and 2 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions src/components/strategies/overview/StrategyContent.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,10 @@
animation: open 300ms ease-out;
}
.strategy-table th {
@apply border-b border-background-800;
font-weight: 400;
color: rgba(255 255 255 / .6);
padding: 16px;
border-bottom: solid 1px rgba(255 255 255 / .4);
text-align: start;
text-wrap: nowrap;
}
Expand All @@ -43,7 +43,7 @@
border-top-right-radius: 8px;
}
.strategy-table tr:not(:last-child) td {
border-bottom: solid 1px rgba(255 255 255 / .4);
@apply border-b border-background-800;
}
.strategy-table tr:last-child td:first-child {
border-bottom-left-radius: 8px;
Expand Down
5 changes: 5 additions & 0 deletions src/utils/helpers/number.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -323,6 +323,11 @@ describe('Test helpers', () => {
'0.00000012345'
);
});

// Very large numbers
test('should return "100.00e+18" for input 1e20', () => {
expect(prettifyNumber(1e20)).toEqual('100.00e+18');
});
});
});

Expand Down
11 changes: 11 additions & 0 deletions src/utils/helpers/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ const subscript = (num: number, formatter: Intl.NumberFormat) => {
return formatter.formatToParts(num).map(transform).join('');
};

export const largeNumbers = (num: number, formatter: Intl.NumberFormat) => {
return formatter.format(num).replace('E', 'e+');
};

interface PrettifyNumberOptions {
abbreviate?: boolean;
currentCurrency?: FiatSymbol;
Expand Down Expand Up @@ -134,6 +138,10 @@ const getIntlOptions = (value: SafeDecimal, options: PrettifyNumberOptions) => {
if (options.abbreviate && value.gte(1_000_000)) {
intlOptions.notation = 'compact';
}
// When ludicrous numbers, use 1E16 notation
if (value.gt(1e16)) {
intlOptions.notation = 'engineering';
}
return intlOptions;
};

Expand Down Expand Up @@ -186,6 +194,9 @@ export function prettifyNumber(
if (!options.noSubscript && num.lt(0.001)) {
return subscript(num.toNumber(), formatter);
}
if (num.gte(1e16)) {
return largeNumbers(num.toNumber(), formatter);
}

return formatter.format(num.toNumber());
}
Expand Down

0 comments on commit 02ab4eb

Please sign in to comment.