Skip to content

Instantly share code, notes, and snippets.

@minitech
Created July 5, 2012 20:11
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save minitech/3056162 to your computer and use it in GitHub Desktop.
Save minitech/3056162 to your computer and use it in GitHub Desktop.
Calculate Total
function calculateTotal(boxes, total) {
boxes.find('option:selected').each(function() {
var m = /\[\+ \$(\d+\.\d+)\]/.exec(this.value);
if(m !== null) {
total += +m[1];
}
});
var decimalPart = (total - Math.floor(total)) * 100;
return '$' + Math.floor(total) + '.' + (decimalPart < 10 ? '0' : '') + decimalPart;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment