otterscan/src/components/formatter.ts

10 lines
353 B
TypeScript
Raw Normal View History

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