All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.slimgears.util.stream.DoubleUtils Maven / Gradle / Ivy

There is a newer version: 0.7.58
Show newest version
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