Created
April 27, 2017 16:57
-
-
Save Phongtlam/0aee497c61842cc9bf165af770a32e4c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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