<divclass="link title"><ahref="/v5/">Documentation</a></div><divclass="base show link depth-1"><ahref="/v5/getting-started/">Getting Started</a></div><divclass="base show link depth-1"><ahref="/v5/concepts/">Ethereum Basics</a></div><divclass="hide link depth-2"><ahref="/v5/concepts/events/">Events</a></div><divclass="hide link depth-2"><ahref="/v5/concepts/gas/">Gas</a></div><divclass="hide link depth-2"><ahref="/v5/concepts/security/">Security</a></div><divclass="base ancestor show link depth-1"><ahref="/v5/api/">Application Programming Interface</a></div><divclass="show link depth-2"><ahref="/v5/api/contract/">Contract Interaction</a></div><divclass="hide link depth-3"><ahref="/v5/api/contract/contract/">Contract</a></div><divclass="hide link depth-3"><ahref="/v5/api/contract/contract-factory/">ContractFactory</a></div><divclass="hide link depth-3"><ahref="/v5/api/contract/example/">Example: ERC-20 Contract</a></div><divclass="show link depth-2"><ahref="/v5/api/signer/">Signers</a></div><divclass="show link depth-2"><ahref="/v5/api/providers/">Providers</a></div><divclass="hide link depth-3"><ahref="/v5/api/providers/provider/">Provider</a></div><divclass="hide link depth-3"><ahref="/v5/api/providers/jsonrpc-provider/">JsonRpcProvider</a></div><divclass="hide link depth-3"><ahref="/v5/api/providers/api-providers/">API Providers</a></div><divclass="hide link depth-3"><ahref="/v5/api/providers/other/">Other Providers</a></div><divclass="hide link depth-3"><ahref="/v5/api/providers/types/">Types</a></div><divclass="ancestor show link depth-2"><ahref="/v5/api/utils/">Utilities</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/abi/">Application Binary Interface</a></div><divclass="hide link depth-4"><ahref="/v5/api/utils/abi/coder/">AbiCoder</a></div><divclass="hide link depth-4"><ahref="/v5/api/utils/abi/formats/">ABI Formats</a></div><divclass="hide link depth-4"><ahref="/v5/api/utils/abi/fragments/">Fragments</a></div><divclass="hide link depth-4"><ahref="/v5/api/utils/abi/interface/">Interface</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/address/">Addresses</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/bignumber/">BigNumber</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/bytes/">Byte Manipulation</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/constants/">Constants</a></div><divclass="myself ancestor ancestor show link depth-3"><ahref="/v5/api/utils/display-logic/">Display Logic and Input</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/encoding/">Encoding Utilities</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/fixednumber/">FixedNumber</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/hashing/">Hashing Algorithms</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/hdnode/">HD Wallet</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/logger/">Logging</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/properties/">Property Utilities</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/signing-key/">Signing Key</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/strings/">Strings</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/transactions/">Transactions</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/web/">Web Utilities</a></div><divclass="show link depth-3"><ahref="/v5/api/utils/wordlists/">Wordlists</a></div><divclass="show link depth-2"><ahref="/v5/api/other/">Other Libraries</a></div><divclass="hide link depth-3"><ahref="/v5/api/other/assembly/">Assembly</a></div><divclass="hide link depth-4"><ahref="/v5/api/other/assembly/dialect/">Ethers ASM Dialect</a></div><divclass="hide link depth-4"><ahref="/v5/api/other/assembly/api/">Utilities</a></div><divclass="hide link depth-4"><ahref="/v5/api/other/assembly/ast/">Abstract Syntax Tree</a></div><divclass="hide link depth-3"><ahref="/v5/api/other/hardware/">Hardware Wallets</a></div><divclass="sho
<divclass="breadcrumbs"><ahref="/v5/">Documentation</a> » <ahref="/v5/api/">API</a> » <ahref="/v5/api/utils/">Utilities</a> » <spanclass="current">Display Logic and Input</span></div>
<aname="display-logic-and-input"></a><h1class="show-anchors"><div>Display Logic and Input<divclass="anchors"><aclass="self"href="/v5/api/utils/display-logic/#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="/v5/api/utils/display-logic/#unit-conversion">parseUnits</a> will parse a string representing ether, such as <codeclass="inline">1.1</code> into a <ahref="/v5/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="/v5/api/utils/display-logic/#unit-conversion">formatUnits</a> will format a <ahref="/v5/api/utils/bignumber/#BigNumberish">BigNumberish</a> into a string, which is useful when displaying a balance.</p>
<aname="display-logic-and-input--units--decimal-count"></a><h3class="show-anchors"><div>Decimal Count<divclass="anchors"><aclass="self"href="/v5/api/utils/display-logic/#display-logic-and-input--units--decimal-count"></a></div></div></h3><p>A <b>Unit</b> can be specified as an number, which indicates the number of decimal places that should be used.</p>
<p><b>Examples:</b></p>
<p><ul><li>1 ether in wei, has <b>18</b> decimal places (i.e. 1 ether represents 10<sup>18</sup> wei) </li><li>1 bitcoin in Satoshi, has <b>8</b> decimal places (i.e. 1 bitcoin represents 10<sup>8</sup> satoshi) </li></ul></p>
<aname="display-logic-and-input--units--named-units"></a><h3class="show-anchors"><div>Named Units<divclass="anchors"><aclass="self"href="/v5/api/utils/display-logic/#display-logic-and-input--units--named-units"></a></div></div></h3><p>There are also several common <b>Named Units</b>, in which case their name (as a string) may be used.</p>
<aname="utils-commify"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">ethers</span><spanclass="symbol">.</span><spanclass="path">utils</span><spanclass="symbol">.</span><spanclass="method">commify</span><spanclass="symbol">(</span><spanclass="param">value</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">string</span><divclass="anchors"><aclass="self"href="/v5/api/utils/display-logic/#utils-commify"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/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>
<aname="utils-formatUnits"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">ethers</span><spanclass="symbol">.</span><spanclass="path">utils</span><spanclass="symbol">.</span><spanclass="method">formatUnits</span><spanclass="symbol">(</span><spanclass="param">value</span><spanclass="symbol">[</span><spanclass="symbol">,</span><spanclass="param">unit</span> = "<spanclass="param">ether</span>" <spanclass="symbol">]</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns">string</span><divclass="anchors"><aclass="self"href="/v5/api/utils/display-logic/#utils-formatUnits"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/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="utils-parseUnits"></a><divclass="property show-anchors"><divclass="signature"><spanclass="path">ethers</span><spanclass="symbol">.</span><spanclass="path">utils</span><spanclass="symbol">.</span><spanclass="method">parseUnits</span><spanclass="symbol">(</span><spanclass="param">value</span><spanclass="symbol">[</span><spanclass="symbol">,</span><spanclass="param">unit</span> = "<spanclass="param">ether</span>" <spanclass="symbol">]</span><spanclass="symbol">)</span><spanclass="arrow">⇒</span><spanclass="returns"><ahref="/v5/api/utils/bignumber/">BigNumber</a></span><divclass="anchors"><aclass="self"href="/v5/api/utils/display-logic/#utils-parseUnits"></a><aclass="source"href="https://github.com/ethers-io/ethers.js/blob/master/packages/units/src.ts/index.ts#L69">source</a></div></div><divclass="body"><p>Returns a <ahref="/v5/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>
<divclass="copyright">The content of this site is licensed under the <ahref="https://choosealicense.com/licenses/cc-by-4.0/">Creative Commons License</a>. Generated on July 5, 2020, 12:0am.</div>