mirror of
https://github.com/MikeMcl/decimal.js.git
synced 2024-10-27 20:34:12 +00:00
Add default value to Decimal constructor
- Adding a default value allows Decimal to be constructed without arguments and not throw an error. Javascript primitives like String and Number can be constructed without an argument and this property is useful when using the type with a library like class-transformer. - Assign a default value of zero as the decimal with no constructor argument.
This commit is contained in:
parent
7f01abd83d
commit
5ddbf63040
4
decimal.d.ts
vendored
4
decimal.d.ts
vendored
@ -57,13 +57,13 @@ export declare class Decimal {
|
||||
readonly e: number;
|
||||
readonly s: number;
|
||||
|
||||
constructor(n: Decimal.Value);
|
||||
constructor(n?: Decimal.Value);
|
||||
|
||||
absoluteValue(): Decimal;
|
||||
abs(): Decimal;
|
||||
|
||||
ceil(): Decimal;
|
||||
|
||||
|
||||
clampedTo(min: Decimal.Value, max: Decimal.Value): Decimal;
|
||||
clamp(min: Decimal.Value, max: Decimal.Value): Decimal;
|
||||
|
||||
|
4
decimal.global.d.ts
vendored
4
decimal.global.d.ts
vendored
@ -78,13 +78,13 @@ export declare class Decimal {
|
||||
readonly e: number;
|
||||
readonly s: number;
|
||||
|
||||
constructor(n: DecimalValue);
|
||||
constructor(n?: DecimalValue);
|
||||
|
||||
absoluteValue(): Decimal;
|
||||
abs(): Decimal;
|
||||
|
||||
ceil(): Decimal;
|
||||
|
||||
|
||||
clampedTo(min: Decimal.Value, max: Decimal.Value): Decimal;
|
||||
clamp(min: Decimal.Value, max: Decimal.Value): Decimal;
|
||||
|
||||
|
@ -4283,6 +4283,7 @@
|
||||
*
|
||||
*/
|
||||
function Decimal(v) {
|
||||
if (typeof v === 'undefined') v = 0
|
||||
var e, i, t,
|
||||
x = this;
|
||||
|
||||
|
@ -4279,6 +4279,7 @@ function clone(obj) {
|
||||
*
|
||||
*/
|
||||
function Decimal(v) {
|
||||
if (typeof v === 'undefined') v = 0
|
||||
var e, i, t,
|
||||
x = this;
|
||||
|
||||
|
@ -278,7 +278,6 @@ T('Decimal', function () {
|
||||
t('123.456789', '123.456789');
|
||||
t('123.456789', '+123.456789');
|
||||
|
||||
tx(function () {new Decimal(void 0)}, "void 0");
|
||||
tx(function () {new Decimal('undefined')}, "'undefined'");
|
||||
tx(function () {new Decimal(null)}, "null");
|
||||
tx(function () {new Decimal('null')}, "'null'");
|
||||
|
@ -540,7 +540,6 @@ T('integer pow', function () {
|
||||
t('1.494189395849269188211255039709933309086424259778445906419464942576097148044216376789735318980392750336285644804638743600807550074206128272345650029255016954321611264002141919840462369550905098763723254901675135787504979910497931539962354019230845564318816091666473025536e+126', '-32698949771.110178432792', 12);
|
||||
t('1.1504940871276742926708823617505372960241390892442547940194260102743306128298973371802547471453755938653944600792141533514422490556963535378521856840746722206160260148176604222079226186281680715577736316488196108040509176925372372483300649927835887344415603493563915019264675154039059770309142781930141352329958156926976e+15', '-8.7358521345995835476', 16);
|
||||
|
||||
tx(function () {new Decimal('12.345').pow(void 0)}, ".pow(void 0)");
|
||||
tx(function () {new Decimal('12.345').pow(null)}, ".pow(null)");
|
||||
tx(function () {new Decimal('12.345').pow(true)}, ".pow(true)");
|
||||
tx(function () {new Decimal('12.345').pow(false)}, ".pow(false)");
|
||||
|
Loading…
Reference in New Issue
Block a user