Guest User

Untitled

a guest
Jul 12th, 2018
83
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. var CashAmount = function(value) {
  2. this.totalInPennies = value*100;
  3. };
  4.  
  5. CashAmount.prototype.toDoubleString = function() {
  6. var s = this.totalInPennies+"";
  7. var len = s.length;
  8. s = s.substring(0,len-2) + '.' + s.substring(len-2,len);
  9. return s;
  10. };
  11.  
  12. CashAmount.prototype.toDouble = function() {
  13. var s = this.toDoubleString();
  14. return parseFloat(s);
  15. };
  16.  
  17. CashAmount.prototype.totalInPennies = function() {
  18. return this.totalInPennies;
  19. };
  20.  
  21. CashAmount.prototype.addDoubleAmount = function(value) {
  22. this.totalInPennies += value;
  23. };
  24.  
  25. CashAmount.prototype.quantityOfEachDenomination = function() {
  26. var Denomination = {};
  27. var remains = this.totalInPennies;
  28. Denomination['hundreds'] = Math.floor(remains/10000);
  29. remains %= 10000;
  30. Denomination['hundreds'] = Math.floor(remains/5000);
  31. remains %= 5000;
  32. Denomination['twenties'] = Math.floor(remains/2000);
  33. remains %= 2000;
  34. Denomination['tens'] = Math.floor(remains/1000);
  35. remains %= 1000;
  36. Denomination['fives'] = Math.floor(remains/500);
  37. remains %= 500;
  38. Denomination['ones'] = Math.floor(remains/100);
  39. remains %= 100;
  40. Denomination['quarters'] = Math.floor(remains/25);
  41. remains %= 25;
  42. Denomination['dimes'] = Math.floor(remains/10);
  43. remains %= 10;
  44. Denomination['nickles'] = Math.floor(remains/5);
  45. remains %= 5;
  46. Denomination['pennies'] = remains;
  47. return Denomination;
  48. };
Add Comment
Please, Sign In to add comment