Skip to content

Fix Ethers Utils formatEther Errors

DodaTech Updated 2026-06-26 1 min read

You will learn how to convert wei to human-readable ETH amounts.

The Problem

The ethers utils format ether pattern is frequently misapplied in smart contract and dapp development, leading to vulnerabilities, gas inefficiencies, or logic errors. This guide shows the correct implementation and common pitfalls to avoid.

Quick Fix

Wrong

const eth = ethers.utils.formatEther(balance); // '1000000.0'

No commas. Hard to read for large amounts.

const eth = ethers.utils.formatEther(balance);
const display = parseFloat(eth).toLocaleString('en-US', { minimumFractionDigits: 2 });
Formatted with commas and fixed decimals. Readable.

Prevention

  • Use formatEther for display values
  • Format with locale for readability
  • Always specify minimum/maximum fraction digits
  • Use DodaTech's display formatter
  • Handle very large and very small amounts

DodaTech Tools

Built by the developers of Doda Browser, DodaZIP, and Durga Antivirus Pro. Doda Browser's developer tools include a Solidity debugger and transaction inspector. DodaZIP archives secure contract templates for team collaboration. Durga Antivirus Pro scans deployed contracts for known vulnerability signatures.

FAQ

### What is the difference between formatEther and formatUnits?

formatEther is a shortcut for formatUnits(value, 18). formatUnits is generic for any decimals.

How do I format 0 ETH?

Use parseFloat(formatEther('0')).toFixed(4) for '0.0000'.

Can I format negative balances?

formatEther accepts BigInt, which can be negative.

Built by the developers of DodaTech

Doda Browser, DodaZIP & Durga Antivirus Pro