package cz.senslog.connector.tools.util;

/**
 * The class {@code NumberUtils} represents set of tools for numbers.
 *
 * @author Lukas Cerny
 * @version 1.0
 * @since 1.0
 */
public final class NumberUtils {

    /**
     * Converts Integer value to Float value. Uses functionality of {@see Float#valueOf}
     * and is extended of null value checker.
     * Example:
     *          null    -> null
     *          10      -> 10.0
     *
     * @param value - integer value.
     * @return float value.
     */
    public static Float valueOf(Integer value) {
        return value == null ? null : Float.valueOf(value);
    }

    public static double round(double value, int precision) {
        if (precision < 0) { return value; }
        if (precision == 0) { return Math.round(value); }
        int temp = (int)Math.pow(10, precision);
        return (double)Math.round(value * temp) / temp;
    }

}
