So when we are in web development we want show Currency value with some formatting. Like thousand separator, decimal separator and currency symbol.
I am using below Jquery function to format the currency values.
function formatCurrency(value, decimals, decpoint, separator, symbol) { decimals = (typeof decimals == 'undefined' ? 2 : decimals); decpoint = (typeof decpoint == 'undefined' ? '.' : decpoint); separator = (typeof separator == 'undefined' ? ',' : separator); symbol = (typeof symbol == 'undefined' ? '$' : symbol); var parts = value.toFixed(decimals).toString().split(decpoint); parts[0] = parts[0].replace(/\B(?=(\d{3})+(?!\d))/g, separator); return (symbol + parts.join(decpoint)).toLocaleString(); }
We can format currency value as we required. If we just pass the currency value it will give us value with default formatting.
formatCurrency(5873839) will give us ” $5,873,839.00″