net.osslabz.crypto.CryptoMathUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of crypto-commons Show documentation
Show all versions of crypto-commons Show documentation
Provides common functionality for some of my crypto related projects.
package net.osslabz.crypto;
import java.math.BigDecimal;
import java.math.RoundingMode;
public class CryptoMathUtils {
public static final BigDecimal HUNDRED = BigDecimal.valueOf(100L);
private CryptoMathUtils() {
// intentionally empty
}
public static boolean isLargerZero(BigDecimal value) {
return value != null && value.compareTo(java.math.BigDecimal.ZERO) > 0;
}
public static BigDecimal getPriceDiff(BigDecimal currentPrice, BigDecimal referencePrice) {
return currentPrice != null && referencePrice != null ? currentPrice.subtract(referencePrice).stripTrailingZeros() : null;
}
public static BigDecimal getPriceDiffAsPercentage(BigDecimal currentPrice, BigDecimal referencePrice) {
BigDecimal diffPrice = getPriceDiff(currentPrice, referencePrice);
return diffPrice != null ? diffPrice.divide(referencePrice, 8, RoundingMode.HALF_UP).stripTrailingZeros() : null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy