otterscan/src/components/formatter.ts
2021-08-08 19:49:45 -03:00

10 lines
353 B
TypeScript

import { BigNumber } from "@ethersproject/bignumber";
import { commify, formatUnits } from "@ethersproject/units";
export const formatValue = (value: BigNumber, decimals: number): string => {
const formatted = commify(formatUnits(value, decimals));
return formatted.endsWith(".0")
? formatted.slice(0, formatted.length - 2)
: formatted;
};