dev.aurelium.auraskills.api.util.NumberUtil Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of auraskills-api Show documentation
Show all versions of auraskills-api Show documentation
API for AuraSkills, the ultra-versatile RPG skills plugin for Minecraft
package dev.aurelium.auraskills.api.util;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.NumberFormat;
public class NumberUtil {
private static final NumberFormat zero = new DecimalFormat("#");
private static final NumberFormat one = new DecimalFormat("#.#");
private static final NumberFormat two = new DecimalFormat("#.##");
static {
zero.setRoundingMode(RoundingMode.HALF_UP);
one.setRoundingMode(RoundingMode.HALF_UP);
two.setRoundingMode(RoundingMode.HALF_UP);
}
public static String format0(double input) {
return zero.format(input);
}
public static String format1(double input) {
return one.format(input);
}
public static String format2(double input) {
return two.format(input);
}
public static int toInt(String str) {
return toInt(str, 0);
}
public static int toInt(String str, int defaultValue) {
if (str == null) {
return defaultValue;
}
try {
return Integer.parseInt(str);
} catch (final NumberFormatException nfe) {
return defaultValue;
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy