0

Is it warranted that web3.utils.toWei(web3.utils.fromWei(x)) is equal in numeric value to x (provided that x is a 256 bit number represented as a string)?

If it is not warranted, how to obtain a value not less (maybe a little greater) that x knowing web3.utils.fromWei(x)?

0

The experiment (takes like 15 sec on my i5 processor)

for(let i=0; i<1000000; ++i) {
  x = web3.utils.randomHex(32);
  if(x.replace(/x0*/, "x") !=  web3.utils.toHex(web3.utils.toWei(web3.utils.fromWei(x)))) {
    console.log(x);
    break;
  }
}

shows that in this case rounding errors do not happen.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.