@ethersproject/bignumber
Advanced tools
Comparing version 5.0.0-beta.122 to 5.0.0-beta.123
@@ -25,2 +25,3 @@ import { BytesLike } from "@ethersproject/bytes"; | ||
divUnsafe(other: FixedNumber): FixedNumber; | ||
round(decimals?: number): FixedNumber; | ||
toString(): string; | ||
@@ -27,0 +28,0 @@ toHexString(width?: number): string; |
@@ -213,2 +213,21 @@ "use strict"; | ||
}; | ||
// @TODO: Support other rounding algorithms | ||
FixedNumber.prototype.round = function (decimals) { | ||
if (decimals == null) { | ||
decimals = 0; | ||
} | ||
if (decimals < 0 || decimals > 80 || (decimals % 1)) { | ||
errors.throwArgumentError("invalid decimal cound", "decimals", decimals); | ||
} | ||
// If we are already in range, we're done | ||
var comps = this.toString().split("."); | ||
if (comps[1].length <= decimals) { | ||
return this; | ||
} | ||
// Bump the value up by the 0.00...0005 | ||
var bump = "0." + zeros.substring(0, decimals) + "5"; | ||
comps = this.addUnsafe(FixedNumber.fromString(bump, this.format))._value.split("."); | ||
// Now it is safe to truncate | ||
return FixedNumber.fromString(comps[0] + "." + comps[1].substring(0, decimals)); | ||
}; | ||
FixedNumber.prototype.toString = function () { return this._value; }; | ||
@@ -215,0 +234,0 @@ FixedNumber.prototype.toHexString = function (width) { |
{ | ||
"name": "@ethersproject/bignumber", | ||
"version": "5.0.0-beta.122", | ||
"version": "5.0.0-beta.123", | ||
"description": "BigNumber library used in ethers.js.", | ||
@@ -25,3 +25,3 @@ "main": "index.js", | ||
}, | ||
"tarballHash": "0x147f27db946bc64abf0b634712fa3faeadc2f4b31d44b5d9ed84602cb0c8be50" | ||
"tarballHash": "0xc44f1d04b00cfe6b34f782630529956d529257c4162c0301e9e6426e989562ce" | ||
} |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
29184
713