Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var CashAmount = function (amt){
- this.amt = Math.ceil(amt * 100) / 100;
- this.denomTable = {
- 'hundreds': 100,
- 'fifties': 50,
- 'twenties': 20,
- 'tens': 10,
- 'fives': 5,
- 'ones': 1,
- 'quarters': 0.25,
- 'dimes': 0.10,
- 'nickels': 0.05,
- 'pennies': 0.01
- }
- };
- CashAmount.prototype.totalInPennies = function () {
- return this.amt * 100;
- };
- CashAmount.prototype.addDoubleAmount = function (addAmt) {
- this.amt = Math.ceil( (this.amt * 100) + (addAmt * 100) ) / 100;
- return this.amt;
- };
- CashAmount.prototype.toDouble = function () {
- return this.amt;
- };
- CashAmount.prototype.toDoubleString = function () {
- return JSON.stringify(this.amt);
- };
- CashAmount.prototype.quantityOfEachDenomination = function () {
- var amtToTable = this.amt;
- var returnTable = {
- 'hundreds': 0,
- 'fifties': 0,
- 'twenties': 0,
- 'tens': 0,
- 'fives': 0,
- 'ones': 0,
- 'quarters': 0,
- 'dimes': 0,
- 'nickels': 0,
- 'pennies': 0
- }
- for (var key in this.denomTable){
- if (key === 'pennies'){
- amtToTable = Math.ceil(amtToTable * 100) / 100;
- var bills = Math.floor(amtToTable / this.denomTable[key]);
- } else {
- var bills = Math.floor(amtToTable / this.denomTable[key]);
- }
- if (bills >= 1) {
- returnTable[key] = bills;
- amtToTable = amtToTable - (bills * this.denomTable[key]);
- }
- }
- return returnTable;
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement