com.mageddo.common.monetary.MonetaryMath Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of commons Show documentation
Show all versions of commons Show documentation
Some commons utilities on mageddo environment
package com.mageddo.common.monetary;
public class MonetaryMath {
/**
* Calculate the percentIncrease rate e.g. lower=5, higher=10, percentIncrease = 1.0
* @param lower the value you had before
* @param higher the value you have now
*/
public static Monetary percentIncrease(Monetary lower, Monetary higher){
return higher.divide(lower).substract(Monetary.ONE);
}
public static Monetary margin(Monetary startValue, Monetary finalValue){
return finalValue.substract(startValue).divide(finalValue);
}
public static Monetary min(Monetary a, Monetary b) {
if(a.compareTo(b) < 0) {
return a;
}
return b;
}
public static Monetary max(Monetary a, Monetary b) {
if(a.compareTo(b) > 0) {
return a;
}
return b;
}
public static Monetary pow(Monetary a, Monetary b){
return Monetary.valueOf(Math.pow(a.doubleValue(), b.doubleValue()));
}
public static Monetary pow(Monetary a, int n){
return Monetary.valueOf(a.decimalOf().pow(n));
}
public static Monetary abs(Monetary value) {
if(value.signum() == 0){
return value;
}
return value.multiply(Monetary.valueOf(-1));
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy