Skip to content

Commit

Permalink
add utils to multiply and divide atomic units
Browse files Browse the repository at this point in the history
  • Loading branch information
woodser committed Jan 17, 2025
1 parent fb09b52 commit 7ad5000
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/main/java/monero/common/MoneroUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -591,6 +591,28 @@ public static double atomicUnitsToXmr(BigInteger amountAtomicUnits) {
return new BigDecimal(amountAtomicUnits).divide(new BigDecimal(XMR_AU_MULTIPLIER), 12, RoundingMode.HALF_UP).doubleValue();
}

/**
* Divide atomic units by another atomic units.
*
* @param auDividend atomic units to divide
* @param auDivisor atomic units to divide by
* @return the result in atomic units
*/
public static double divide(BigInteger auDividend, BigInteger auDivisor) {
return new BigDecimal(auDividend).divide(new BigDecimal(auDivisor), 12, RoundingMode.HALF_UP).doubleValue();
}

/**
* Multiply atomic units amount by a double.
*
* @param amount1 atomic units to multiply
* @param amount2 double to multiply by
* @return the result in atomic units
*/
public static BigInteger multiply(BigInteger amount1, double amount2) {
return amount1 == null ? null : new BigDecimal(amount1).multiply(BigDecimal.valueOf(amount2)).setScale(0, RoundingMode.HALF_UP).toBigInteger();
}

/**
* Creates a payment URI from a tx configuration.
*
Expand Down

0 comments on commit 7ad5000

Please sign in to comment.