Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
58
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.37 KB | None | 0 0
  1. var CashAmount = function (amt){
  2. this.amt = Math.ceil(amt * 100) / 100;
  3. this.denomTable = {
  4. 'hundreds': 100,
  5. 'fifties': 50,
  6. 'twenties': 20,
  7. 'tens': 10,
  8. 'fives': 5,
  9. 'ones': 1,
  10. 'quarters': 0.25,
  11. 'dimes': 0.10,
  12. 'nickels': 0.05,
  13. 'pennies': 0.01
  14. }
  15.  
  16. };
  17.  
  18. CashAmount.prototype.totalInPennies = function () {
  19. return this.amt * 100;
  20. };
  21.  
  22. CashAmount.prototype.addDoubleAmount = function (addAmt) {
  23. this.amt = Math.ceil( (this.amt * 100) + (addAmt * 100) ) / 100;
  24. return this.amt;
  25. };
  26.  
  27. CashAmount.prototype.toDouble = function () {
  28. return this.amt;
  29. };
  30.  
  31. CashAmount.prototype.toDoubleString = function () {
  32. return JSON.stringify(this.amt);
  33. };
  34.  
  35. CashAmount.prototype.quantityOfEachDenomination = function () {
  36. var amtToTable = this.amt;
  37.  
  38. var returnTable = {
  39. 'hundreds': 0,
  40. 'fifties': 0,
  41. 'twenties': 0,
  42. 'tens': 0,
  43. 'fives': 0,
  44. 'ones': 0,
  45. 'quarters': 0,
  46. 'dimes': 0,
  47. 'nickels': 0,
  48. 'pennies': 0
  49. }
  50.  
  51. for (var key in this.denomTable){
  52. if (key === 'pennies'){
  53. amtToTable = Math.ceil(amtToTable * 100) / 100;
  54. var bills = Math.floor(amtToTable / this.denomTable[key]);
  55. } else {
  56. var bills = Math.floor(amtToTable / this.denomTable[key]);
  57. }
  58.  
  59. if (bills >= 1) {
  60. returnTable[key] = bills;
  61. amtToTable = amtToTable - (bills * this.denomTable[key]);
  62. }
  63. }
  64. return returnTable;
  65. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement