-
Notifications
You must be signed in to change notification settings - Fork 0
/
mathstuff.js
38 lines (32 loc) · 943 Bytes
/
mathstuff.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
(function( $ ) {
$.fn.sum = function() {
var return_value = 0;
this.each(function() {
return_value += convert_to_a_float($(this).val());
});
return return_value;
};
$.fn.multiply = function(){
var value = 1;
the_set_includes_a_valid_number = false;
this.each(function(){
if (this_is_a_valid_number($(this).val()))
{
value *= convert_to_a_float($(this).val());
the_set_includes_a_valid_number = true;
}
});
return the_set_includes_a_valid_number ? value : 0;
};
$.formatAsDollars = function(value){
var valueAsFloat = convert_to_a_float(value);
valueAsFloat = Math.round(valueAsFloat * 100) / 100;
return valueAsFloat.toFixed(2);
};
function this_is_a_valid_number(value){
return isNaN(value) == false;
}
function convert_to_a_float(value){
return this_is_a_valid_number(value) ? parseFloat(value) : 0;
}
})(jQuery);