Skip to content
Ethereum unit conversion.
JavaScript
Branch: master
Clone or download

Latest commit

Latest commit 3e4d606 Jun 9, 2016

Files

Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
test
.gitignore Initial version Mar 22, 2016
.travis.yml
LICENSE Initial version Mar 22, 2016
README.md
index.js Round properly to avoid fractions of wei Apr 13, 2016
package.json
units.json Change units.js to JSON Apr 13, 2016

README.md

ethereumjs-units

NPM Package Build Status Coverage Status Gitter or #ethereumjs on freenode

Unit conversion utility.

There are two methods:

  • convert(value, unitFrom, unitTo) - convert a value between two units
  • lazyConvert(value, unitTo) - include unit type in the input and the output

The value and the output in all cases is a string.

Examples

Units.convert('1', 'eth', 'wei') // '1000000000000000000'
Units.convert('1', 'wei', 'eth') // '0.000000000000000001'
Units.convert('1', 'finney', 'eth') // '0.001'

Units.lazyConvert('1 eth', 'wei') // '1000000000000000000 wei'
Units.lazyConvert('1 wei', 'eth') // '0.000000000000000001 eth'
Units.lazyConvert('1 finney', 'eth') // '0.001 eth'

Units

Units are defined in units.json. It is compatible with web3.js and additionally includes ETH.

You can’t perform that action at this time.