ether-unit-converter
Version:
The utility functions provide a conversation assortment of common utility functions, and can easily convert Wei to value and value to Wei without a round number.
30 lines (22 loc) • 754 B
JavaScript
/**
* This test cases passes
*/
const { WebUtils } = require("ether-unit-convertor");
/**
* For Wei to Value
*/
let value = WebUtils.fromWei("100000", 6);
console.log("Value for 6 decimal", value); //: 0.1
value = WebUtils.fromWei("10000000000", 10);
console.log("Value for 10 decimal", value); //: 1
value = WebUtils.fromWei("420120012000000000", 18);
console.log("Value for 18 decimal", value); //: 0.420120012
/**
* For Value to Wei
*/
let wei = WebUtils.toWei("0.1", 6); //:100000
console.log("Wei for 6 decimal", wei);
wei = WebUtils.toWei("1", 10);
console.log("Wei for 10 decimal", wei); //: 10000000000
wei = WebUtils.toWei("0.420120012", 18); //: 420120012000000000
console.log("Wei for 18 decimal", wei);