Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- class Decimal {
- constructor(value, decimalPlaces = 2) {
- this.value = value;
- this.decimalPlaces = decimalPlaces;
- }
- valueOf() {
- let pow = Math.pow(10, this.decimalPlaces);
- let retv = Math.round(this.value * pow) / pow;
- return retv;
- }
- toString() {
- return ''+this.valueOf();
- }
- toJSON() {
- return this.valueOf();
- }
- }
Add Comment
Please, Sign In to add comment