I have created a calculator that shows the output of savings with a specific calculation. I just need the result to be formatted with commas and to be currency so it does not show every number after the decimal. For example if the outcome was:
$2500.566695969 I would only want it to show: $2,500.56
I hope that makes sense, I tried a couple of things to get the comma in the right place but nothing worked. I am a bit newer to jQuery and this is my first attempt at a calculator like this. Any help is really appreciated. Below is my code.
function calculate() {
var savingsVal = (jQuery('#savingsVal').val());
var totalSavings = 0;
var regType = (jQuery('#reg-type').val());
if (filterValues(savingsVal)) {
totalSavings = savingsVal * 0.15 * 3 - regType * 3;
}
jQuery('#totalSavings').val('$' + totalSavings);
}
function filterValues(eVal) {
return true;
}
jQuery('.results-area').hide();
jQuery('#calculator').submit(function(e) {
e.preventDefault();
calculate();
jQuery('.results-area').show("slow");
jQuery(this).text( jQuery(this).submit().replace(/(\d)(?=(\d\d\d)+(?!\d))/g, "$1,") );
});