Class MathUtils
java.lang.Object
org.xrpl.xrpl4j.codec.binary.math.MathUtils
Utility functions for XRPL-related math operations.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic intgetExponent(BigDecimal value) Get the exponent value forvalue.static BigIntegertoPaddedBigInteger(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.
-
Constructor Details
-
MathUtils
public MathUtils()
-
-
Method Details
-
getExponent
Get the exponent value forvalue.- Parameters:
value- ABigDecimalto obtain the exponent from.- Returns:
- An int representing the exponent value of
value.
-
toPaddedBigInteger
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 haveexpectedDigits. Examples:toPaddedBigInteger(1, 4)yields 1000toPaddedBigInteger(1.23, 4)yields 1230toPaddedBigInteger(0.1234, 4)yields 1234toPaddedBigInteger(0.1234, 3)throws an IllegalArgumentException as the numberToPad cannot fit in 3 digits.
- Parameters:
numberToPad- ABigDecimalto pad.expectedDigits- An int representing the total number of digits thatnumberToPadis expected to have.- Returns:
- A
BigIntegerthat is correctly padded. - Throws:
IllegalArgumentException- ifnumberToPaddoes not have a total digit count equal toexpectedDigits.
-