<html><head><title>Display Logic and Input</title><linkrel="stylesheet"type="text/css"href="/static/style.css"></head><body><divclass="sidebar"><divclass="header"><divclass="logo"><ahref="/"><divclass="image"></div><divclass="name">ethers</div><divclass="version">v5.0-beta</div></a></div></div><divclass="toc"><div><divclass="link title"><ahref="/">Documentation</a></div><divclass="base show link depth-1"><ahref="/getting-started/">Getting Started</a></div><divclass="hide link depth-2"><ahref="/getting-started/#installing">Installing</a></div><divclass="hide link depth-2"><ahref="/getting-started/#importing">Importing</a></div><divclass="base show link depth-1"><ahref="/concepts/">Concepts</a></div><divclass="hide link depth-2"><ahref="/concepts/events/">Events</a></div><divclass="hide link depth-3"><ahref="/concepts/events/#solidity-topics">Solidity Topics</a></div><divclass="hide link depth-2"><ahref="/concepts/gas/">Gas</a></div><divclass="hide link depth-3"><ahref="/concepts/gas/#gas-price">Gas Price</a></div><divclass="hide link depth-3"><ahref="/concepts/gas/#gas-limit">Gas Limit</a></div><divclass="base ancestor show link depth-1"><ahref="/api/">Application Programming Interface</a></div><divclass="show link depth-2"><ahref="/api/contract/">Contracts</a></div><divclass="hide link depth-3"><ahref="/api/contract/#buckets">Buckets</a></div><divclass="show link depth-2"><ahref="/api/signer/">Signers</a></div><divclass="hide link depth-3"><ahref="/api/signer/#signer">Signer</a></div><divclass="hide link depth-3"><ahref="/api/signer/#wallet-inherits-signer">Wallet inherits Signer</a></div><divclass="show link depth-2"><ahref="/api/providers/">Providers</a></div><divclass="hide link depth-3"><ahref="/api/providers/provider/">Provider</a></div><divclass="hide link depth-4"><ahref="/api/providers/provider/#accounts-methods">Accounts Methods</a></div><divclass="hide link depth-4"><ahref="/api/providers/provider/#blocks-methods">Blocks Methods</a></div><divclass="hide link depth-4"><ahref="/api/providers/provider/#ethereum-naming-service-(ens)-methods">Ethereum Naming Service (ENS) Methods</a></div><divclass="hide link depth-4"><ahref="/api/providers/provider/#logs-methods">Logs Methods</a></div><divclass="hide link depth-4"><ahref="/api/providers/provider/#network-status-methods">Network Status Methods</a></div><divclass="hide link depth-4"><ahref="/api/providers/provider/#transactions-methods">Transactions Methods</a></div><divclass="hide link depth-4"><ahref="/api/providers/provider/#event-emitter-methods">Event Emitter Methods</a></div><divclass="hide link depth-4"><ahref="/api/providers/provider/#inspection-methods">Inspection Methods</a></div><divclass="hide link depth-3"><ahref="/api/providers/jsonrpc-provider/">JSON-RPC Provider</a></div><divclass="hide link depth-4"><ahref="/api/providers/jsonrpc-provider/#jsonrpcprovider">JsonRpcProvider</a></div><divclass="hide link depth-4"><ahref="/api/providers/jsonrpc-provider/#jsonrpcsigner">JsonRpcSigner</a></div><divclass="hide link depth-4"><ahref="/api/providers/jsonrpc-provider/#jsonrpcuncheckedsigner">JsonRpcUncheckedSigner</a></div><divclass="hide link depth-3"><ahref="/api/providers/api-providers/">API Providers</a></div><divclass="hide link depth-4"><ahref="/api/providers/api-providers/#etherscanprovider">EtherscanProvider</a></div><divclass="hide link depth-4"><ahref="/api/providers/api-providers/#infuraprovider">InfuraProvider</a></div><divclass="hide link depth-4"><ahref="/api/providers/api-providers/#nodesmithprovider">NodesmithProvider</a></div><divclass="hide link depth-4"><ahref="/api/providers/api-providers/#alchemyprovider">AlchemyProvider</a></div><divclass="hide link depth-4"><ahref="/api/providers/api-providers/#cloudfrontprovider">CloudfrontProvider</a></div><divclass="hide link depth-3"><ahref="/api/providers/other/">Other Providers</a></div><divclass="hide link depth-4"><ahref="/api/providers/other/#fallbackprovider">FallbackProvider</a></div><divclass="hidelinkde
<aname="display-logic-and-input"></a><h1class="show-anchors"><div>Display Logic and Input<divclass="anchors"><aclass="self"href="#display-logic-and-input"></a></div></div></h1>
<p>When creating an Application, it is useful to convert between user-friendly strings (usually displaying <b>ether</b>) and the machine-readable values that contracts and maths depend on (usually in <b>wei</b>).</p><p>For example, a Wallet may specify the balance in ether, and gas prices in gwei for the User Interface, but when sending a transaction, both must be specified in wei.</p><p>The <ahref="/api/utils/display-logic/#unit-conversion">parseUnits</a> will parse a string representing ether, such as <codeclass="inline">1.1</code> into a <ahref="/api/utils/bignumber/">BigNumber</a> in wei, and is useful when a user types in a value, such as sending 1.1 ether.</p><p>The <ahref="/api/utils/display-logic/#unit-conversion">formatUnits</a> will format a <ahref="/api/utils/bignumber/#bignumberish">BigNumberish</a> into a string, which is useful when displaying a balance.</p>
<p>The <i>unit</i> specified may be an integer, which indicates how many decimal place the unit has. For example, 1 ether has 18 decimal places for wei, and if this library were used with Bitcoin, 1 BTC has 8 decimal places for satoshis.</p>
<p>In addition to specifying <i>unit</i> as a number of decimals, there are several common units, which can be passed in as a string:</p><ul><li><b>wei</b>— 0</li><li><b>kwei</b>— 3</li><li><b>mwei</b>— 6</li><li><b>gwei</b>— 9</li><li><b>szabo</b>— 12</li><li><b>finney</b>— 15</li><li><b>ether</b>— 18</li></ul>
<aname="util-commify"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">commify</span> ( <spanclass="param">value</span> ) <spanclass="arrow">⇒</span><spanclass="returns">string</span><divclass="anchors"><aclass="self"href="#util-commify"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/units/src.ts/index.ts#L23">source</a></div></div><divclass="body"><p>Returns a string with value grouped by 3 digits, separated by <codeclass="inline">,</code>.</p></div></div>
<aname="util-formatunits"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">formatUnits</span> ( <spanclass="param">value</span> [ , <spanclass="param">unit</span> = <spanclass="default-value">"</span><spanclass="param">ether</span>" ] ) <spanclass="arrow">⇒</span><spanclass="returns">string</span><divclass="anchors"><aclass="self"href="#util-formatunits"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/units/src.ts/index.ts#L61">source</a></div></div><divclass="body"><p>Returns a string representation of <i>value</i> formatted with <i>unit</i> digits (if it is a number) or to the unit specified (if a string).</p></div></div>
<aname="util-parseunits"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">parseUnits</span> ( <spanclass="param">value</span> [ , <spanclass="param">unit</span> = <spanclass="default-value">"</span><spanclass="param">ether</span>" ] ) <spanclass="arrow">⇒</span><spanclass="returns"><ahref="/api/utils/bignumber/">BigNumber</a></span><divclass="anchors"><aclass="self"href="#util-parseunits"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/units/src.ts/index.ts#L69">source</a></div></div><divclass="body"><p>Returns a <ahref="/api/utils/bignumber/">BigNumber</a> representation of <i>value</i>, parsed with <i>unit</i> digits (if it is a number) or from the unit specified (if a string).</p></div></div>
<aname="util-parseether"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">utils</span> . <spanclass="method">parseEther</span> ( <spanclass="param">value</span> ) <spanclass="arrow">⇒</span><spanclass="returns"><ahref="/api/utils/bignumber/">BigNumber</a></span><divclass="anchors"><aclass="self"href="#util-parseether"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/ethers-v5-beta/packages/units/src.ts/index.ts#L81">source</a></div></div><divclass="body"><p>The equivalent to calling <codeclass="inline">parseUnits(value, "ether")</code>.</p></div></div><divclass="footer"><divclass="nav previous"><ahref="/api/utils/constants/"><spanclass="arrow">←</span>Constants</a></div><divclass="nav next"><ahref="/api/utils/fixednumber/">FixedNumber<spanclass="arrow">→</span></a></div></div><divclass="copyright">The content of this site is licensed under the <ahref="https://choosealicense.com/licenses/cc-by-4.0/">Creative Commons Attribution 4.0 International License</a>.</div></div><scriptsrc="/script.js"type="text/javascript"></script></body></html><!-- ContentHash:0570507a83e1a505205532b8db4096e852c1c53ceb18651cacde98974a70713e -->