Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

More refactoring

  • Loading branch information...
commit 18421680ea2d9bc2dcf2b18bf13431ccf56b7a46 1 parent 4401d21
@darrencauthon authored
Showing with 5 additions and 7 deletions.
  1. +5 −7 mathstuff.js
View
12 mathstuff.js
@@ -1,9 +1,9 @@
(function( $ ) {
+
$.fn.sum = function() {
var return_value = 0;
this.each(function() {
- if (this_is_a_valid_number($(this).val()))
- return_value += convert_to_a_float($(this).val());
+ return_value += convert_to_a_float($(this).val());
});
return return_value;
};
@@ -22,9 +22,7 @@
};
$.formatAsDollars = function(value){
- if (isNaN(value)) return "0.00";
- if (value == 0) return "0.00";
- var valueAsFloat = parseFloat(value);
+ var valueAsFloat = convert_to_a_float(value);
valueAsFloat = Math.round(valueAsFloat * 100) / 100;
return valueAsFloat.toFixed(2);
};
@@ -34,7 +32,7 @@
}
function convert_to_a_float(value){
- return parseFloat(value);
+ return this_is_a_valid_number(value) ? parseFloat(value) : 0;
}
-})( jQuery );
+})(jQuery);
Please sign in to comment.
Something went wrong with that request. Please try again.