I would like to format my numbers to always display 2 decimal places, rounding where applicable.
Examples:
number display ------ ------- 1
function currencyFormat (num) { return "$" + num.toFixed(2).replace(/(\d)(?=(\d{3})+(?!\d))/g, "$1,") } console.info(currencyFormat(2665)); // $2,665.00 console.info(currencyFormat(102665)); // $102,665.00