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

META-INF.resources.bower_components.globalize.src.util.number.to-precision.js Maven / Gradle / Ivy

There is a newer version: 0.66.0.1
Show newest version
define(function () {

    /**
     * toPrecision( number, precision, round )
     *
     * @number (Number)
     *
     * @precision (Number) significant figures precision (not decimal precision).
     *
     * @round (Function)
     *
     * Return number.toPrecision( precision ) using the given round function.
     */
    return function (number, precision, round) {
        var roundOrder;

        // Get number at two extra significant figure precision.
        number = number.toPrecision(precision + 2);

        // Then, round it to the required significant figure precision.
        roundOrder = Math.ceil(Math.log(Math.abs(number)) / Math.log(10));
        roundOrder -= precision;

        return round(number, {exponent: roundOrder});
    };

});




© 2015 - 2024 Weber Informatics LLC | Privacy Policy