Skip to content

Commit

Permalink
Fixed FixedNumber unguarded constructor and added isZero (#898).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo committed Jun 29, 2020
1 parent c53864d commit 08c74e9
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions packages/bignumber/src.ts/fixednumber.ts
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,12 @@ export class FixedFormat {
readonly _multiplier: string;

constructor(constructorGuard: any, signed: boolean, width: number, decimals: number) {
if (constructorGuard !== _constructorGuard) {
logger.throwError("cannot use FixedFormat construtor; use FixedFormat.from", Logger.errors.UNSUPPORTED_OPERATION, {
operation: "new FixedFormat"
});
}

this.signed = signed;
this.width = width;
this.decimals = decimals;
Expand Down Expand Up @@ -185,6 +191,12 @@ export class FixedNumber {
constructor(constructorGuard: any, hex: string, value: string, format?: FixedFormat) {
logger.checkNew(new.target, FixedNumber);

if (constructorGuard !== _constructorGuard) {
logger.throwError("cannot use FixedNumber construtor; use FixedNumber.from", Logger.errors.UNSUPPORTED_OPERATION, {
operation: "new FixedFormat"
});
}

this.format = format;
this._hex = hex;
this._value = value;
Expand Down Expand Up @@ -247,6 +259,10 @@ export class FixedNumber {
return FixedNumber.fromString(comps[0] + "." + comps[1].substring(0, decimals));
}

isZero(): boolean {
return (this._value === "0.0");
}


toString(): string { return this._value; }

Expand Down

0 comments on commit 08c74e9

Please sign in to comment.