Round a float number

/**
 * @description To round a float number
 * @param {Number|String} value
 * @param {Number|String} decimals
 * @returns {Number} Floating Point Number with the given precision
 */
const roundFloat = (value, decimals) => {
    decimals = (decimals) ? decimals : 2;
    return Number(Math.round(parseFloat(value) + 'e' + parseInt(decimals)) + 'e-' + parseInt(decimals));
};

Leave a comment

Your email address will not be published. Required fields are marked *