首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >将电子天平转换成乙醚

将电子天平转换成乙醚
EN

Ethereum用户
提问于 2017-12-01 11:50:46
回答 2查看 4.4K关注 0票数 3
代码语言:javascript
复制
public BigInteger getBalance(String address) 
{
    /*Web3j web3j  */

   createEthreumConnection();
   EthGetBalance ethGetBalance = null;
   try {
      ethGetBalance = web.ethGetBalance(address, DefaultBlockParameterName.LATEST).sendAsync().get();
   } catch (InterruptedException e) {               
      logger.error("Interrupted Exception "+e);
   } catch (ExecutionException e) {         
      logger.error("ExecutionException Exception "+e);
   }
   return ethGetBalance.getBalance();
}

我正在使用上面的代码来获得虚空平衡,但是以给定的4555500000格式获取的余额,我想要显示为#en0# balance.For示例比特币提供的balance.For。

EN

回答 2

Ethereum用户

回答已采纳

发布于 2017-12-05 05:19:31

@Luiz Soares感谢你给我提供了关于魏的价值的线索,但是提供的解决方案没有起作用,me.After,一些挖掘文档,得到了解决方案

( Convert.fromWei(ethGetBalance.getBalance().toString(),Unit.ETHER);

票数 7
EN

Ethereum用户

发布于 2017-12-01 12:00:57

你得到了魏的价值

web3.eth.getBalance返回给定地址的当前余额的BigNumber实例(以魏为单位)。https://github.com/ethereum/wiki/wiki/JavaScript-API#returns-33

转换到以太:var value = web3.fromWei('21000000000000', 'ether');

https://github.com/ethereum/wiki/wiki/JavaScript-API#web3fromwei

票数 2
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/32208

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档