https://github.com/ethereumjs/ethereumjs-units
Ethereum unit conversion.
https://github.com/ethereumjs/ethereumjs-units
Last synced: about 2 months ago
JSON representation
Ethereum unit conversion.
- Host: GitHub
- URL: https://github.com/ethereumjs/ethereumjs-units
- Owner: ethereumjs
- License: mit
- Created: 2016-03-22T14:53:48.000Z (over 9 years ago)
- Default Branch: master
- Last Pushed: 2018-07-21T23:54:07.000Z (over 7 years ago)
- Last Synced: 2025-03-30T16:02:09.036Z (9 months ago)
- Language: JavaScript
- Size: 7.81 KB
- Stars: 42
- Watchers: 25
- Forks: 19
- Open Issues: 7
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ethereumjs-units
[](https://www.npmjs.org/package/ethereumjs-units)
[](https://travis-ci.org/ethereumjs/ethereumjs-units)
[](https://coveralls.io/r/ethereumjs/ethereumjs-units)
[](https://gitter.im/ethereum/ethereumjs-lib) 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
```js
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](https://github.com/ethereum/web3.js) and additionally includes `ETH`.