[Ethereum] Convert ethereum balance getting in biginteger to ether

etherweb3j

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();
}

I am using the above code for getting the ethereum balance but the balance fetched in given format 4555500000 , I want to be shown as Ethereum balance.For example Bitcoin j provides MonetaryFormat.BTC.noCode().format(addressBalance)

Best Answer

@Luiz Soares Thank you for giving me the clue of the value being in WEI but solution provided didn't worked me.After some digging the documentation again got the solution

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

Related Topic