@@ -44,19 +44,6 @@ d5 = new Decimal(0.1); // Actually Decimal("0.1000000000000000055511151231257827
4444d6 = new Decimal (123n );
4545```
4646
47- ## Static Methods
48-
49- ### Decimal.** from** (_ value_ : string | number | bigint | Decimal) : Decimal
50-
51- Converts a value to a ` Decimal ` . Unlike the constructor, this method also accepts existing ` Decimal ` objects (returning them unchanged).
52-
53- ``` js
54- Decimal .from (" 123.45" ); // => Decimal("123.45")
55- Decimal .from (123.45 ); // => Decimal("123.45")
56- Decimal .from (123n ); // => Decimal("123")
57- Decimal .from (existingDecimal); // => existingDecimal (same object)
58- ```
59-
6047## Special Values
6148
6249### NaN (Not a Number)
@@ -87,43 +74,43 @@ posInf.add(new Decimal("1")).toString(); // => "Infinity"
8774new Decimal (" 1" ).divide (new Decimal (" 0" )).toString (); // => "Infinity"
8875```
8976
90- ## Properties
77+ ## Methods
9178
92- ### ** magnitude ** : bigint
79+ ### ** significand() ** : bigint
9380
9481Returns the significand (mantissa) of the decimal number as a bigint, without regard to the exponent.
9582
9683``` js
97- new Decimal (" 123.45" ).magnitude ; // => 12345n
98- new Decimal (" 0.00123" ).magnitude ; // => 123n
84+ new Decimal (" 123.45" ).significand () ; // => 12345n
85+ new Decimal (" 0.00123" ).significand () ; // => 123n
9986```
10087
101- ### ** exponent** : number
88+ ### ** exponent() ** : number
10289
10390Returns the base-10 exponent of the decimal number.
10491
10592``` js
106- new Decimal (" 123.45" ).exponent ; // => -2 (representing 12345 × 10^-2)
107- new Decimal (" 1.23e5" ).exponent ; // => 3 (representing 123 × 10^3)
93+ new Decimal (" 123.45" ).exponent () ; // => -2 (representing 12345 × 10^-2)
94+ new Decimal (" 1.23e5" ).exponent () ; // => 3 (representing 123 × 10^3)
10895```
10996
110- ### ** isNaN** : boolean
97+ ### ** isNaN() ** : boolean
11198
11299Returns true if the value is NaN (Not a Number).
113100
114101``` js
115- new Decimal (" NaN" ).isNaN ; // => true
116- new Decimal (" 123" ).isNaN ; // => false
102+ new Decimal (" NaN" ).isNaN () ; // => true
103+ new Decimal (" 123" ).isNaN () ; // => false
117104```
118105
119- ### ** isFinite** : boolean
106+ ### ** isFinite() ** : boolean
120107
121108Returns true if the value is finite (not NaN or infinity).
122109
123110``` js
124- new Decimal (" 123" ).isFinite ; // => true
125- new Decimal (" Infinity" ).isFinite ; // => false
126- new Decimal (" NaN" ).isFinite ; // => false
111+ new Decimal (" 123" ).isFinite () ; // => true
112+ new Decimal (" Infinity" ).isFinite () ; // => false
113+ new Decimal (" NaN" ).isFinite () ; // => false
127114```
128115
129116## Arithmetic Methods
@@ -215,7 +202,7 @@ Rounds to a given number of decimal places.
215202** Parameters:**
216203
217204- ` scale ` (number): Number of decimal places to round to (default: 0)
218- - ` options.roundingMode ` (string): One of "ceil", "floor", "trunc", "halfEven" (default), or "halfAwayFromZero "
205+ - ` options.roundingMode ` (string): One of "ceil", "floor", "trunc", "halfEven" (default), or "halfExpand "
219206
220207``` js
221208const d = new Decimal (" 123.456" );
@@ -286,35 +273,35 @@ new Decimal("123.45").toString(); // => "123.45"
286273new Decimal (" 1.23e5" ).toString (); // => "123000"
287274```
288275
289- ### ** toFixed** (_ digits_ : number) : string
276+ ### ** toFixed** ({ _ digits_ : number} ) : string
290277
291278Returns a string with a fixed number of decimal places.
292279
293280``` js
294281const d = new Decimal (" 123.456" );
295- d .toFixed (0 ); // => "123"
296- d .toFixed (2 ); // => "123.46"
297- d .toFixed (5 ); // => "123.45600"
282+ d .toFixed ({ digits : 0 } ); // => "123"
283+ d .toFixed ({ digits : 2 } ); // => "123.46"
284+ d .toFixed ({ digits : 5 } ); // => "123.45600"
298285```
299286
300- ### ** toExponential** (_ fractionDigits _ ? : number) : string
287+ ### ** toExponential** ({ _ digits _ : number}? ) : string
301288
302289Returns a string in exponential notation.
303290
304291``` js
305292const d = new Decimal (" 123.456" );
306293d .toExponential (); // => "1.23456e+2"
307- d .toExponential (2 ); // => "1.23e+2"
294+ d .toExponential ({ digits : 2 } ); // => "1.23e+2"
308295```
309296
310- ### ** toPrecision** (_ precision _ : number) : string
297+ ### ** toPrecision** ({ _ digits _ : number} ) : string
311298
312299Returns a string with the specified number of significant digits.
313300
314301``` js
315302const d = new Decimal (" 123.456" );
316- d .toPrecision (2 ); // => "1.2e+2"
317- d .toPrecision (5 ); // => "123.46"
303+ d .toPrecision ({ digits : 2 } ); // => "1.2e+2"
304+ d .toPrecision ({ digits : 5 } ); // => "123.46"
318305```
319306
320307### ** toNumber** () : number
@@ -328,17 +315,14 @@ new Decimal("123.456789012345678901234567890123").toNumber(); // => 123.45678901
328315
329316### ** toBigInt** () : bigint
330317
331- Converts to a BigInt, truncating any fractional part.
318+ Converts to a BigInt, throwing if the number isn't actually an integer:
332319
333320``` js
334- new Decimal (" 123.45 " ).toBigInt (); // => 123n
335- new Decimal (" 123.99" ).toBigInt (); // => 123n
321+ new Decimal (" 123" ).toBigInt (); // => 123n
322+ new Decimal (" 123.99" ).toBigInt (); // throws
336323```
337324
338- ### ** valueOf** () : string
325+ ### ** valueOf** ()
339326
340- Returns the string representation. This method is called by JavaScript when a primitive value is needed.
341-
342- ``` js
343- new Decimal (" 123.45" ).valueOf (); // => "123.45"
327+ This method always throws, since there is currently no primitive that would exactly match the numeric representation of a Decimal.
344328```
0 commit comments