Skip to content

Commit

Permalink
feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
StefanBratanov committed Sep 16, 2024
1 parent 888fffe commit f10536c
Showing 1 changed file with 4 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,14 @@

public class Converter {

static BigDecimal gweiToEthFactor = BigDecimal.TEN.pow(9);

public static String weiToEth(final UInt256 wei) {
final BigDecimal result = Convert.fromWei(wei.toDecimalString(), Convert.Unit.ETHER);
return result.setScale(6, RoundingMode.HALF_UP).toString();
final BigDecimal eth = Convert.fromWei(wei.toDecimalString(), Convert.Unit.ETHER);
return eth.setScale(6, RoundingMode.HALF_UP).toString();
}

public static String gweiToEth(final UInt64 gwei) {
return new BigDecimal(gwei.bigIntegerValue())
.divide(gweiToEthFactor, 6, RoundingMode.HALF_UP)
.toString();
final BigDecimal wei = Convert.toWei(gwei.toString(), Unit.GWEI);
return weiToEth(UInt256.valueOf(wei.toBigInteger()));
}

public static UInt64 weiToGwei(final UInt256 wei) {
Expand Down

0 comments on commit f10536c

Please sign in to comment.