Guest User

Untitled

a guest
May 16th, 2018
119
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.39 KB | None | 0 0
  1. class Decimal {
  2. constructor(value, decimalPlaces = 2) {
  3. this.value = value;
  4. this.decimalPlaces = decimalPlaces;
  5. }
  6.  
  7. valueOf() {
  8. let pow = Math.pow(10, this.decimalPlaces);
  9. let retv = Math.round(this.value * pow) / pow;
  10. return retv;
  11. }
  12.  
  13. toString() {
  14. return ''+this.valueOf();
  15. }
  16.  
  17. toJSON() {
  18. return this.valueOf();
  19. }
  20. }
Add Comment
Please, Sign In to add comment