tokilabs / lang

Extends TypeScript/Javascript with basic classes and functions

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Decimal is not using precision

svallory opened this issue · comments

Precision is fixed at 2 despite the constructor accepting a precision parameter.

https://github.com/cashfarm/node-lang/blob/master/src/decimal.ts

Resolved in the last commit: d4f0883

lang/src/decimal.ts

Lines 9 to 37 in d4f0883

@FQN("@tokilabs/lang:Decimal")
export class Decimal extends NumberWrapper {
public precision: number;
get primitiveValue(): number {
return parseFloat(this.toFixed(this.precision));
}
/**
* Creates an instance of Decimal.
*
* @param {(number | string)} value
*
* @memberOf Decimal
*/
constructor(value: number | string, precision?: number) {
if (!precision) precision = 2;
if (typeof value === "string") {
value = parseFloat(value);
}
if (typeof value !== "number" || isNaN(value)) {
throw new Error(
"Decimal constructor requires a number or the string representation of a number."
);
}
super(parseFloat((value ? value : 0).toFixed(precision)));
this.precision = precision;
}

The issue was resolved in the latest version of the package. I will close the issue.