* @return string
*/
var currencyTemplate;
- CRM.formatMoney = function(value, format) {
+ CRM.formatMoney = function(value, format, onlyNumber) {
var decimal, separator, sign, i, j, result;
if (value === 'init' && format) {
currencyTemplate = format;
return;
}
format = format || currencyTemplate;
+ onlyNumber = onlyNumber || false;
result = /1(.?)234(.?)56/.exec(format);
if (result === null) {
return 'Invalid format passed to CRM.formatMoney';
i = parseInt(value = Math.abs(value).toFixed(2)) + '';
j = ((j = i.length) > 3) ? j % 3 : 0;
result = sign + (j ? i.substr(0, j) + separator : '') + i.substr(j).replace(/(\d{3})(?=\d)/g, "$1" + separator) + (2 ? decimal + Math.abs(value - i).toFixed(2).slice(2) : '');
+ if ( onlyNumber ) {
+ return result;
+ }
return format.replace(/1.*234.*56/, result);
};
else {
var feeTotal = Number((taxRate/100) * (allMemberships[memType]['total_amount_numeric'] * term))+Number(allMemberships[memType]['total_amount_numeric'] * term );
}
- cj("#total_amount").val( feeTotal.toFixed(2) );
+ cj("#total_amount").val(CRM.formatMoney(feeTotal, '', true));
}
else {
if (taxRate) {
var feeTotal = parseFloat(Number((taxRate/100) * allMemberships[memType]['total_amount'])+Number(allMemberships[memType]['total_amount_numeric'])).toFixed(2);
- cj("#total_amount").val( feeTotal );
+ cj("#total_amount").val(CRM.formatMoney(feeTotal, '', true));
}
else {
var feeTotal = allMemberships[memType]['total_amount'];
var term = cj("#num_terms").val();
if (term) {
var renewTotal = allMemberships[memType]['total_amount_numeric'] * term;
- cj("#total_amount").val(renewTotal.toFixed(2));
+ cj("#total_amount").val(CRM.formatMoney(renewTotal, '', true));
}
else {
cj("#total_amount").val(allMemberships[memType]['total_amount']);