
com.slimgears.util.stream.DoubleUtils Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of stream-utils Show documentation
Show all versions of stream-utils Show documentation
General purpose utils / module: stream-utils
package com.slimgears.util.stream;
import java.text.DecimalFormat;
public class DoubleUtils {
private final static DecimalFormat DECIMAL_FORMAT = new DecimalFormat();
static {
DECIMAL_FORMAT.setMinimumFractionDigits(0);
DECIMAL_FORMAT.setGroupingUsed(false);
}
public static double round(double value, int precisionDigits) {
double scale = Math.pow(10, precisionDigits);
return Math.round(value * scale) / scale;
}
public static double floor(double value, int precisionDigits) {
double scale = Math.pow(10, precisionDigits);
return Math.floor(value * scale) / scale;
}
public static String toString(double value) {
return DECIMAL_FORMAT.format(value);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy