Skip to content

Commit

Permalink
Merge branch 'feat/sub-num' into tmp/20241226
Browse files Browse the repository at this point in the history
  • Loading branch information
vvvvvv1vvvvvv committed Dec 25, 2024
2 parents 6b9cb57 + d0aef61 commit ef37d29
Showing 1 changed file with 16 additions and 1 deletion.
17 changes: 16 additions & 1 deletion src/ui/utils/number.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
import BigNumber from 'bignumber.js';

const Sub_Numbers = '₀₁₂₃₄₅₆₇₈₉';

export const splitNumberByStep = (
num: number | string,
step = 3,
Expand Down Expand Up @@ -105,7 +107,20 @@ export const formatPrice = (price: string | number) => {
// @ts-expect-error
if (price < 0.00001) {
if (price.toString().length > 10) {
return Number(price).toExponential(4);
const s = new BigNumber(price).precision(4).toFormat();
const ss = s.replace(/^0.(0*)?(?:.*)/, (l, z) => {
const zeroLength = z.length;

const sub = `${zeroLength}`
.split('')
.map((x) => Sub_Numbers[x as any])
.join('');

const end = s.slice(zeroLength + 2);
return `0.0${sub}${end}`;
});

return ss;
}
return price.toString();
}
Expand Down

0 comments on commit ef37d29

Please sign in to comment.