28 lines
753 B
Java
28 lines
753 B
Java
|
package cc.fascinated.bat.common;
|
||
|
|
||
|
import lombok.experimental.UtilityClass;
|
||
|
|
||
|
import java.text.DecimalFormat;
|
||
|
import java.text.DecimalFormatSymbols;
|
||
|
|
||
|
/**
|
||
|
* @author Fascinated (fascinated7)
|
||
|
*/
|
||
|
@UtilityClass
|
||
|
public final class MathUtils {
|
||
|
/**
|
||
|
* Format a number to a specific amount of decimal places.
|
||
|
*
|
||
|
* @param number the number to format
|
||
|
* @param additional the additional decimal places to format
|
||
|
* @return the formatted number
|
||
|
*/
|
||
|
public static double format(double number, int additional) {
|
||
|
return Double.parseDouble(
|
||
|
new DecimalFormat("#.#" + "#".repeat(Math.max(0, additional - 1)),
|
||
|
new DecimalFormatSymbols()
|
||
|
).format(number)
|
||
|
);
|
||
|
}
|
||
|
}
|