Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var CashAmount = function(value) {
- this.totalInPennies = value*100;
- };
- CashAmount.prototype.toDoubleString = function() {
- var s = this.totalInPennies+"";
- var len = s.length;
- s = s.substring(0,len-2) + '.' + s.substring(len-2,len);
- return s;
- };
- CashAmount.prototype.toDouble = function() {
- var s = this.toDoubleString();
- return parseFloat(s);
- };
- CashAmount.prototype.totalInPennies = function() {
- return this.totalInPennies;
- };
- CashAmount.prototype.addDoubleAmount = function(value) {
- this.totalInPennies += value;
- };
- CashAmount.prototype.quantityOfEachDenomination = function() {
- var Denomination = {};
- var remains = this.totalInPennies;
- Denomination['hundreds'] = Math.floor(remains/10000);
- remains %= 10000;
- Denomination['hundreds'] = Math.floor(remains/5000);
- remains %= 5000;
- Denomination['twenties'] = Math.floor(remains/2000);
- remains %= 2000;
- Denomination['tens'] = Math.floor(remains/1000);
- remains %= 1000;
- Denomination['fives'] = Math.floor(remains/500);
- remains %= 500;
- Denomination['ones'] = Math.floor(remains/100);
- remains %= 100;
- Denomination['quarters'] = Math.floor(remains/25);
- remains %= 25;
- Denomination['dimes'] = Math.floor(remains/10);
- remains %= 10;
- Denomination['nickles'] = Math.floor(remains/5);
- remains %= 5;
- Denomination['pennies'] = remains;
- return Denomination;
- };
Add Comment
Please, Sign In to add comment