daily pastebin goal
83%
SHARE
TWEET

Untitled

a guest May 16th, 2018 88 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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. }
RAW Paste Data
Top