Skip to content

Instantly share code, notes, and snippets.

@Phongtlam
Created April 27, 2017 16:57
Show Gist options
  • Save Phongtlam/0aee497c61842cc9bf165af770a32e4c to your computer and use it in GitHub Desktop.
Save Phongtlam/0aee497c61842cc9bf165af770a32e4c to your computer and use it in GitHub Desktop.
var CashAmount = function(val) {
val = val.toFixed(2)
this.value = val;
}
CashAmount.prototype.totalInPennies = function() {
var array = this.value.split('.');
var first = array[0] + '00';
return parseInt(first) + parseInt(array[1]);
}
CashAmount.prototype.addDoubleAmount = function(val) {
var amt = this.totalInPennies();
val = new CashAmount(val)
val = val.totalInPennies()
this.value = ((amt + val)/100).toFixed(2);
}
CashAmount.prototype.toDouble = function()
var cash = new CashAmount(10.50);
console.log(cash.totalInPennies())
cash.addDoubleAmount(29.33);
cash.totalInPennies()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment