I would like to format my numbers to always display 2 decimal places, rounding where applicable.
Examples:
number display ------ ------- 1
Try below code:
function numberWithCommas(number) { var newval = parseFloat(Math.round(number * 100) / 100).toFixed(2); return newval.toString().replace(/\B(?=(\d{3})+(?!\d))/g, ","); }