jQuery.math 1.0

( by Mark Kockerbeck )
various jQuery helper methods for common math operations
<script type="text/javascript" src="jquery.1.3.2.js"></script>
<script type="text/javascript" src="jquery.math.1.0.js"></script>
<script type="text/javascript">
  $(function(){
     // Set Tax Row
     $('table td.tax').multiply('.amount', 0.07);
        
     // Set totals 
     $('table td.amount').subtotal().runningTotal();
      
     // Stddev      
     $('#stdDevExample').text('Stddev is: ' + $('span.data').stddev());

     // Sum example
     $('#someSum').text('The sum is: ' + $('span.someSum').sum());
      
     // Totals
     $('#taxTotal').text($('td.tax').sum());
     $('#runningTotal').text($('td.runningTotal').sum()+' (meaningless)');
     $('#total').text($('td.amount').sum());
     $('#subtotal').text($('td.subtotal').sum());

     // Average
     $('#invoiceAverage').text($('td.amount').average());
     
      // Round Example
      $('#roundExample').text($('span.roundExample').round());
      $('#roundExample2').text($('span.roundExample').round(3));
  });  
</script>

$.subtotal & $.runningTotal Example

Note how the order of the Customer ID does not matter. Subtotals appear on the last row.

Anything with this color is generated by jQuery.math.

Check Number Customer ID Product ID Tax Invoice Amount Running Total Subtotal
1003 MARK001 CAMERA00356 345.45
1004 MARK001 CAMERA00356 345.45
53455 PHIL045 PS3000145 599.99
1005 MARK001 CAMERA00356 6945.45
1006 MARK001 CAMERA00356 345.45
53455 PHIL045 XBOX0360 299.99
4345 SPEN010 LAPTOP00432 2,003.04
4346 SPEN010 LAPTOP00532 1,203.04
Totals:
Average:

$.stddev Example

2 4 4 4 5 5 7 9

$.sum Example

(pun intended)
2.43435 2fs 43 products -32 0 wd40 32

$.getNumber Example

1234 I declare a thumb war, 5678 try to keep your thumb up straight.

(number is extracted as-is via: $.math.settings.addExtractedNumbers = false; $.math.settings.extractNumbers = true;)

(numbers are extracted & added up via: $.math.settings.addExtractedNumbers = true; $.math.settings.extractNumbers = true;)

$.round Example

2.7182818284590452353602874713527

(decimals for all equations set via: $.math.settings.decimals = NNN;)

(decimals set via: $('selector').round(3);)