To fix a float number to specified decimal parts

/**
 * @description To fix a float number to specified decimal parts
 * @param {Number|String} value
 * @param {Number|String} decimals
 * @returns {Number|String}
 */
const fixFloat = (value, decimals) => {
    decimals = (decimals) ? decimals : 2;
    // return roundFloat(parseFloat(value), parseInt(decimals)).toFixed(parseInt(decimals));
    return parseFloat(value).toFixed(decimals);
};

Leave a comment

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