daily pastebin goal
83%
SHARE
TWEET

Untitled

a guest May 16th, 2018 89 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
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top