Value in wei (as bigint, string, or number)
Number of decimal places to display (default: 4)
Formatted ETH value as string
Converts wei (smallest ETH unit) to human-readable ETH format. 1 ETH = 10^18 wei. The function truncates rather than rounds to ensure predictable display in financial contexts.
Edge Cases:
// Standard conversions
formatEth(1000000000000000000n) // Returns: "1.0000"
formatEth(1500000000000000000n, 2) // Returns: "1.50"
formatEth("2000000000000000000") // Returns: "2.0000"
// Edge cases
formatEth(1000000000000000n) // Returns: "0.0010" (0.001 ETH)
formatEth(100000000000000n) // Returns: "0.0001"
formatEth(10000000000000n) // Returns: "0.0000" (truncated)
formatEth(-1000000000000000000n) // Returns: "-1.000"
Format wei value to ETH with specified decimal places