Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. var CashAmount = function(money) {
  2. this.money = money; //number
  3. this.moneyStr = this.money.toFixed(2); //string
  4. this.integer = Number(this.moneyStr.split('.')[0]);
  5. this.decimal = Number(this.moneyStr.split('.')[1]);
  6. }
  7.  
  8. CashAmount.prototype.totalInPennies = function() {
  9. return this.money * 100;
  10. }
  11.  
  12. CashAmount.prototype.addDoubleAmount = function(addMoney) {
  13.  
  14. this.addMoneyStr = addMoney.toFixed(2);
  15. this.addInteger = Number(this.addMoneyStr.split('.')[0]);
  16. this.addDecimal = Number(this.addMoneyStr.split('.')[1]);
  17.  
  18. var tempDecimal = this.addDecimal + this.decimal;
  19.  
  20. if (tempDecimal >= 100) {
  21. var totalDecimal = (tempDecimal / 100).toFixed(2).split('.')[1];
  22. var moreInteger = (tempDecimal / 100).toFixed(2).split('.')[0];
  23. var totalInteger = this.addInteger + this.integer + Number(moreInteger);
  24.  
  25. this.money = Number(([totalInteger, totalDecimal]).join('.'));
  26. this.moneyStr = this.money.toFixed(2); //string
  27. this.integer = Number(this.moneyStr.split('.')[0]);
  28. this.decimal = Number(this.moneyStr.split('.')[1]);
  29. } else {
  30. var totalDecimal = tempDecimal;
  31. var totalInteger = this.addInteger + this.integer;
  32.  
  33. this.money = Number(([totalInteger, totalDecimal]).join('.'));
  34. this.moneyStr = this.money.toFixed(2); //string
  35. this.integer = Number(this.moneyStr.split('.')[0]);
  36. this.decimal = Number(this.moneyStr.split('.')[1]);
  37. }
  38. }
  39.  
  40.  
  41. CashAmount.prototype.quantityOfEachDenomination = function() {
  42. var quantity = {};
  43. quantity.hundreds = Math.floor(this.integer / 100);
  44. quantity.fifties = Math.floor((this.integer % 100) / 50);
  45. quantity.twenties = Math.floor(((this.integer % 100) % 50 ) / 20);
  46. quantity.tens = Math.floor((((this.integer % 100) % 50) % 20) / 10);
  47. quantity.fives = Math.floor(((((this.integer % 100) % 50) % 20) %10) / 5);
  48. quantity.ones = ((((this.integer % 100) % 50) % 20) %10) % 5;
  49. quantity.quarters = Math.floor(this.decimal / 25);
  50. quantity.dimes = Math.floor((this.decimal % 25) / 10);
  51. quantity.nickels = Math.floor(((this.decimal % 25) %10) / 5);
  52. quantity.penny = ((this.decimal % 25) %10) % 5;
  53. return quantity;
  54. }
  55.  
  56.  
  57.  
  58. CashAmount.prototype.toDouble = function() {
  59.  
  60. }
  61.  
  62. CashAmount.prototype.toDoubleString = function() {
  63.  
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement