Skip to content

Commit

Permalink
Merge pull request #1466 from bancorprotocol/issue-#1465
Browse files Browse the repository at this point in the history
Prevent scientific display in inputs
  • Loading branch information
GrandSchtroumpf authored Sep 3, 2024
2 parents 1c13fd2 + 8e95ab3 commit 6abf465
Show file tree
Hide file tree
Showing 11 changed files with 9 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.
4 changes: 4 additions & 0 deletions src/utils/helpers/number.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,13 @@ describe('Test helpers', () => {
test('formatNumber', () => {
expect(formatNumber('')).toBe('');
expect(formatNumber('.')).toBe('0');
expect(formatNumber('0.0000000')).toBe('0');
expect(formatNumber('.1')).toBe('0.1');
expect(formatNumber('1.1010')).toBe('1.101');
expect(formatNumber('01.100')).toBe('1.1');
expect(formatNumber('01.00')).toBe('1');
expect(formatNumber('1.000000000100')).toBe('1.0000000001');
expect(formatNumber('.000000000100')).toBe('0.0000000001');
});
describe('prettifyNumber', () => {
test('should return 0 for input lower then 0', () => {
Expand Down
7 changes: 5 additions & 2 deletions src/utils/helpers/number.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,10 @@ export const sanitizeNumber = (input: string, precision?: number): string => {
export const formatNumber = (value: string) => {
if (!value) return '';
if (value === '.') return '0';
return new SafeDecimal(value).toString();
return new SafeDecimal(value)
.toFixed(100)
.replace(lastZero, '')
.replace(/\.+$/, ''); // Remove "." if it's the last character
};

const getDisplayCurrency = (currency: string) => {
Expand Down Expand Up @@ -219,7 +222,7 @@ export const roundSearchParam = (param?: string | number) => {
maxDecimals += decimals.match(firstZero)?.[0].length ?? 0;
}
const roundedDecimals = decimals.slice(0, maxDecimals).replace(lastZero, '');
return [radix, roundedDecimals].filter((v) => !!v).join('.');
return [radix || '0', roundedDecimals].filter((v) => !!v).join('.');
};

export const tokenAmount = (
Expand Down

0 comments on commit 6abf465

Please sign in to comment.