Class MathUtils

java.lang.Object
org.xrpl.xrpl4j.codec.binary.math.MathUtils

public class MathUtils extends Object
Utility functions for XRPL-related math operations.
  • Constructor Details

    • MathUtils

      public MathUtils()
  • Method Details

    • getExponent

      public static int getExponent(BigDecimal value)
      Get the exponent value for value.
      Parameters:
      value - A BigDecimal to obtain the exponent from.
      Returns:
      An int representing the exponent value of value.
    • toPaddedBigInteger

      public static BigInteger toPaddedBigInteger(BigDecimal numberToPad, int expectedDigits)
      XRPL amounts are right-padded with 0s, so both 1, 10, 100 are converted to 10000000000000000, which, when combined with the exponent field can be used to reconstruct the actual decimal value. The resulting value will have expectedDigits. Examples:
      • toPaddedBigInteger(1, 4) yields 1000
      • toPaddedBigInteger(1.23, 4) yields 1230
      • toPaddedBigInteger(0.1234, 4) yields 1234
      • toPaddedBigInteger(0.1234, 3) throws an IllegalArgumentException as the numberToPad cannot fit in 3 digits.
      Parameters:
      numberToPad - A BigDecimal to pad.
      expectedDigits - An int representing the total number of digits that numberToPad is expected to have.
      Returns:
      A BigInteger that is correctly padded.
      Throws:
      IllegalArgumentException - if numberToPad does not have a total digit count equal to expectedDigits.