Advertisement
Guest User

Untitled

a guest
Sep 21st, 2017
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.03 KB | None | 0 0
  1. //Prompt: tackling floating-point imprecision with the CashAmount class
  2.  
  3. function CashAmount(amount) {
  4. this.amount = amount;
  5. }
  6.  
  7.  
  8. CashAmount.prototype.totalInPennies = function() {
  9. return this.amount * 100;
  10. }
  11.  
  12.  
  13. CashAmount.prototype.addDoubleAmount = function(addAmount) {
  14. this.amount = Math.ceil( (this.amount * 100) + (addAmount * 100) ) / 100;
  15. return this.amount;
  16. }
  17.  
  18.  
  19. CashAmount.prototype.toDouble = function() {
  20. return this.amount;
  21. }
  22.  
  23. CashAmount.prototype.toDoubleString = function() {
  24. return JSON.stringify(this.amountt);
  25. }
  26.  
  27.  
  28. CashAmount.prototype.quantityOfEachDenomination = function() {
  29.  
  30. }
  31. // class TestSuite {
  32. // runTests() {
  33. // // your code here
  34. // }
  35.  
  36. // testFoo() { /* some test code */ }
  37. // testBar() { /* some test code */ }
  38. // testBaz() { /* some test code */ }
  39. // }
  40.  
  41. // const suite = new TestSuite();
  42. // suite.runTests(); // testFoo, testBar, and testBaz are executed
  43.  
  44.  
  45. // var cash = new CashAmount(11.22)
  46.  
  47. // console.log('totalIn Pennies ',cash.totalInPennies())
  48.  
  49. // console.log(cash.addDoubleAmount(29.33))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement