1# @arkts.math.Decimal (High-Precision Math Library Decimal)
2
3The Decimal module provides a high-precision math library that offers the capability of high-precision floating-point arithmetic.
4
5> **NOTE**
6>
7> The initial APIs of this module are supported since API version 12. Newly added APIs will be marked with a superscript to indicate their earliest API version.
8
9
10## Modules to Import
11
12```ts
13import { Decimal } from '@kit.ArkTS';
14```
15
16## Value
17
18type Value = string | number | Decimal
19
20Enumerates the value types available for constructing a decimal.
21
22The actual value type can be the union of the types listed below.
23
24**Atomic service API**: This API can be used in atomic services since API version 12.
25
26**System capability**: SystemCapability.Utils.Lang
27
28| Type               | Description                          |
29| ------------------- | ------------------------------ |
30| string              | The value can be any string.|
31| number              | The value can be any number.|
32| [Decimal](#decimal) | The value is a decimal.     |
33
34## Rounding
35
36type Rounding = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8
37
38Enumerates the rounding modes available.
39
40The actual rounding mode can be the union of the types listed below.
41
42**Atomic service API**: This API can be used in atomic services since API version 12.
43
44**System capability**: SystemCapability.Utils.Lang
45
46| Type| Description                                                        |
47| ---- | ------------------------------------------------------------ |
48| 0    | Rounds in such a way that the result heads away from zero. It is the same as [Decimal.ROUND_UP](#constants).       |
49| 1    | Rounds in such a way that the result heads towards zero. It is the same as [Decimal.ROUND_DOWN](#constants).     |
50| 2    | Rounds towards positive infinity. It is the same as [Decimal.ROUND_CEILING](#constants).    |
51| 3    | Rounds towards negative infinity. It is the same as [Decimal.ROUND_FLOOR](#constants).      |
52| 4    | Rounds towards the nearest neighbor, and if both neighbors are equidistant, rounds away from zero. It is the same as [Decimal.ROUND_HALF_UP](#constants).|
53| 5    | Rounds towards the nearest neighbor, and if both neighbors are equidistant, rounds towards zero. It is the same as [Decimal.ROUND_HALF_DOWN](#constants).|
54| 6    | Rounds towards the nearest neighbor, and if both neighbors are equidistant, rounds towards the even neighbor. It is the same as [Decimal.ROUND_HALF_EVEN](#constants).|
55| 7    | Rounds towards the nearest neighbor, and if both neighbors are equidistant, rounds towards positive infinity. It is the same as [Decimal.ROUND_HALF_CEILING](#constants).|
56| 8    | Rounds towards the nearest neighbor, and if both neighbors are equidistant, rounds towards negative infinity. It is the same as [Decimal.ROUND_HALF_FLOOR](#constants).|
57
58## Modulo
59
60type Modulo = Rounding | 9
61
62Enumerates the rounding modes available in the modulo operation.
63
64The actual rounding mode can be the union of the types listed below.
65
66**Atomic service API**: This API can be used in atomic services since API version 12.
67
68**System capability**: SystemCapability.Utils.Lang
69
70| Type                  | Description                                                        |
71| ---------------------- | ------------------------------------------------------------ |
72| [Rounding](#rounding) | Same rounding mode as that represented by [Rounding](#constants). |
73| 9                      | Positive remainder from Euclid's division. It is the same as [Decimal.EUCLID](#constants).|
74
75## DecimalConfig
76
77Describes the configuration of a **Decimal** object. You can call [Decimal.set](#set) to set these properties.
78
79### Properties
80
81**Atomic service API**: This API can be used in atomic services since API version 12.
82
83**System capability**: SystemCapability.Utils.Lang
84
85| Name     | Type                  | Read-Only| Mandatory| Description                                                        |
86| --------- | ---------------------- | ---- | ---- | ------------------------------------------------------------ |
87| precision | number                 | No  | No  | Maximum number of significant digits of the result of an operation. The value range is [1, 1e9], and the default value is **20**.    |
88| rounding  | [Rounding](#rounding) | No  | No  | Rounding mode. The value is an integer ranging from 0 to 8, and the default value is **4**.                 |
89| toExpNeg  | number                 | No  | No  | Negative exponent value at and below which [toString](#tostring) returns exponential notation. The value range is [-9e15, 0], and the default value is **-7**.|
90| toExpPos  | number                 | No  | No  | Positive exponent value at and above which [toString](#tostring) returns exponential notation. The value range is [0, 9e15], and the default value is **21**.|
91| minE      | number                 | No  | No  | Minimum negative exponents. A decimal with an exponent less than this minimum value underflows towards zero. The value range is [-9e15, 0], and the default value is **-9e15**.|
92| maxE      | number                 | No  | No  | Maximum positive exponent. A decimal with an exponent greater than this maximum value overflows to infinity. The value range is [0, 9e15], and the default value is **9e15**.|
93| crypto    | boolean                | No  | No  | Whether to use a pseudorandom number for encryption. The default value is **false**. The capability is not supported yet, and error code 10200061 is reported if it is used. |
94| modulo    | [Modulo](#modulo)      | No  | No  | Rounding mode used in the modulo operation. The value is an integer ranging from 0 to 9, and the default value is **1**.   |
95| defaults  | boolean                | No  | No  | Whether the default value is used if no value is passed in for a property. The value **true** means that the default value is used, and **false** means the opposite. The default value is **true**.|
96
97## Decimal
98
99Decimal with any precision.
100
101### Properties
102
103**Atomic service API**: This API can be used in atomic services since API version 12.
104
105**System capability**: SystemCapability.Utils.Lang
106
107| Name| Type    | Read-Only| Mandatory| Description                                     |
108| ---- | -------- | ---- | ---- | ----------------------------------------- |
109| d    | number[] | Yes  | Yes  | Digits in the integer part and factional part of a decimal.|
110| e    | number   | Yes  | Yes  | Exponent in a decimal.|
111| s    | number   | Yes  | Yes  | Sign in a decimal.            |
112
113### Constants
114
115**Atomic service API**: This API can be used in atomic services since API version 12.
116
117**System capability**: SystemCapability.Utils.Lang
118
119| Name              | Type  | Value  | Description                                                        |
120| ------------------ | ------ | ---- | ------------------------------------------------------------ |
121| ROUND_UP           | number | 0    | Rounds in such a way that the result heads away from zero. In the modulo operation, if the dividend is negative, the remainder is positive; otherwise, the remainder is negative.|
122| ROUND_DOWN         | number | 1    | Rounds in such a way that the result heads towards zero. In the modulo operation, the remainder has the same sign as the dividend, and truncating division is used.|
123| ROUND_CEILING      | number | 2    | Rounds towards positive infinity.                                          |
124| ROUND_FLOOR        | number | 3    | Rounds towards negative infinity. In the modulo operation, the remainder has the same sign as the dividend.          |
125| ROUND_HALF_UP      | number | 4    | Rounds towards the nearest neighbor, and if both neighbors are equidistant, rounds away from zero.          |
126| ROUND_HALF_DOWN    | number | 5    | Rounds towards the nearest neighbor, and if both neighbors are equidistant, rounds towards zero.          |
127| ROUND_HALF_EVEN    | number | 6    | Rounds towards the nearest neighbor, and if both neighbors are equidistant, rounds towards the even neighbor. In the modulo operation, the modulo function in IEEE 754 is used.|
128| ROUND_HALF_CEILING | number | 7    | Rounds towards the nearest neighbor, and if both neighbors are equidistant, rounds towards positive infinity.        |
129| ROUND_HALF_FLOOR   | number | 8    | Rounds towards the nearest neighbor, and if both neighbors are equidistant, rounds towards negative infinity.        |
130| EUCLID             | number | 9    | Always a positive remainder in the modulo operation. The Euclid's division formula is used: q = sign(x) * floor(a / abs(x)).|
131
132### constructor
133
134constructor(n: Value)
135
136A constructor used to create a **Decimal** object.
137
138**Atomic service API**: This API can be used in atomic services since API version 12.
139
140**System capability**: SystemCapability.Utils.Lang
141
142**Parameters**
143
144| Name| Type           | Mandatory| Description                   |
145| ------ | --------------- | ---- | ----------------------- |
146| n      | [Value](#value) | Yes  | Initial value used to create the **Decimal** object.|
147
148**Error codes**
149
150For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
151
152| ID| Error Message                                                    |
153| -------- | ------------------------------------------------------------ |
154| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
155
156**Example**
157
158```ts
159let data: Decimal = new Decimal(5);
160console.info("test Decimal constructor:" + data.toString()); // 'test Decimal constructor:5'
161```
162
163### abs
164
165abs(): Decimal
166
167Returns a new **Decimal** object representing the absolute value of this decimal.
168
169**Atomic service API**: This API can be used in atomic services since API version 12.
170
171**System capability**: SystemCapability.Utils.Lang
172
173**Return value**
174
175| Type               | Description                               |
176| ------------------- | ----------------------------------- |
177| [Decimal](#decimal) | **Decimal** object representing the absolute value.|
178
179**Example**
180
181```ts
182let data: Decimal = new Decimal(-0.5).abs();
183console.info("test Decimal abs:" + data.toString()); // 'test Decimal abs:0.5'
184```
185
186### floor
187
188floor(): Decimal
189
190Returns a new **Decimal** object representing the nearest integer to which this decimal is rounded down.
191
192**Atomic service API**: This API can be used in atomic services since API version 12.
193
194**System capability**: SystemCapability.Utils.Lang
195
196**Return value**
197
198| Type               | Description                           |
199| ------------------- | ------------------------------- |
200| [Decimal](#decimal) | **Decimal** object representing the nearest integer rounded.|
201
202**Example**
203
204```ts
205let data: Decimal = new Decimal(1.8).floor();
206console.info("test Decimal floor:" + data.toString()); // 'test Decimal floor:1'
207```
208
209### ceil
210
211ceil(): Decimal
212
213Returns a new **Decimal** object representing the nearest integer to which this decimal is rounded up.
214
215**Atomic service API**: This API can be used in atomic services since API version 12.
216
217**System capability**: SystemCapability.Utils.Lang
218
219**Return value**
220
221| Type               | Description                           |
222| ------------------- | ------------------------------- |
223| [Decimal](#decimal) | **Decimal** object representing the nearest integer rounded.|
224
225**Example**
226
227```ts
228let data: Decimal = new Decimal(1.8).ceil();
229console.info("test Decimal ceil:" + data.toString()); // 'test Decimal ceil:2'
230```
231
232### trunc
233
234trunc(): Decimal
235
236Returns a new **Decimal** object representing the integer part truncated from this decimal.
237
238**Atomic service API**: This API can be used in atomic services since API version 12.
239
240**System capability**: SystemCapability.Utils.Lang
241
242**Return value**
243
244| Type               | Description                           |
245| ------------------- | ------------------------------- |
246| [Decimal](#decimal) | **Decimal** object representing the integer part.|
247
248**Example**
249
250```ts
251let data: Decimal = new Decimal(2.5).trunc();
252console.info("test Decimal trunc:" + data.toString()); // 'test Decimal trunc:2'
253```
254
255### clamp
256
257clamp(min: Value, max: Value): Decimal
258
259Returns a new **Decimal** object representing the value clamped to the inclusive range of **min** and **max**.
260
261**Atomic service API**: This API can be used in atomic services since API version 12.
262
263**System capability**: SystemCapability.Utils.Lang
264
265**Parameters**
266
267| Name| Type           | Mandatory| Description                    |
268| ------ | --------------- | ---- | ------------------------ |
269| min    | [Value](#value) | Yes  | Lower bound of the range. This value is inclusive.|
270| max    | [Value](#value) | Yes  | Upper bound of the range. This value is inclusive.|
271
272**Return value**
273
274| Type               | Description                             |
275| ------------------- | --------------------------------- |
276| [Decimal](#decimal) | **Decimal** object representing a value within the range.|
277
278**Error codes**
279
280For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Utils Error Codes](errorcode-utils.md).
281
282| ID| Error Message                                                    |
283| -------- | ------------------------------------------------------------ |
284| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
285| 10200001 | The value of 'min' is out of range.                          |
286
287**Example**
288
289```ts
290let data: Decimal = new Decimal(10.1).clamp(0, 10);
291console.info("test Decimal clamp:" + data.toString()); // 'test Decimal clamp:10'
292```
293
294
295
296### add
297
298add(n: Value): Decimal;
299
300Returns a new **Decimal** object representing the sum of adding the specified number *n* to this decimal.
301
302You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
303
304**Atomic service API**: This API can be used in atomic services since API version 12.
305
306**System capability**: SystemCapability.Utils.Lang
307
308**Parameters**
309
310| Name| Type           | Mandatory| Description            |
311| ------ | --------------- | ---- | ---------------- |
312| n      | [Value](#value) | Yes  | Addend.|
313
314**Return value**
315
316| Type   | Description                           |
317| ------- | ------------------------------- |
318| [Decimal](#decimal) | **Decimal** object representing the sum.|
319
320**Error codes**
321
322For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
323
324| ID| Error Message                                                    |
325| -------- | ------------------------------------------------------------ |
326| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
327
328**Example**
329
330```ts
331let data: Decimal = new Decimal(0.5).add(0.5);
332console.info("test Decimal add:" + data.toString()); // 'test Decimal add:1'
333```
334
335### sub
336
337sub(n: Value): Decimal
338
339Returns a new **Decimal** object representing the difference of subtracting the specified number *n* from this decimal.
340
341You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
342
343**Atomic service API**: This API can be used in atomic services since API version 12.
344
345**System capability**: SystemCapability.Utils.Lang
346
347**Parameters**
348
349| Name| Type           | Mandatory| Description            |
350| ------ | --------------- | ---- | ---------------- |
351| n      | [Value](#value) | Yes  | Subtrahend.|
352
353**Return value**
354
355| Type   | Description                           |
356| ------- | ------------------------------- |
357| [Decimal](#decimal) | **Decimal** object representing the difference.|
358
359**Error codes**
360
361For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
362
363| ID| Error Message                                                    |
364| -------- | ------------------------------------------------------------ |
365| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
366
367**Example**
368
369```ts
370let data: Decimal = new Decimal(1).sub(0.5);
371console.info("test Decimal sub:" + data.toString()); // 'test Decimal sub:0.5'
372```
373
374### mul
375
376mul(n: Value): Decimal
377
378Returns a new **Decimal** object representing the product of multiplying this decimal by the specified number *n*.
379
380You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
381
382**Atomic service API**: This API can be used in atomic services since API version 12.
383
384**System capability**: SystemCapability.Utils.Lang
385
386**Parameters**
387
388| Name| Type           | Mandatory| Description            |
389| ------ | --------------- | ---- | ---------------- |
390| n      | [Value](#value) | Yes  | Multiplicand.|
391
392**Return value**
393
394| Type   | Description                           |
395| ------- | ------------------------------- |
396| [Decimal](#decimal) | **Decimal** object representing the product.|
397
398**Error codes**
399
400For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
401
402| ID| Error Message                                                    |
403| -------- | ------------------------------------------------------------ |
404| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
405
406**Example**
407
408```ts
409let data: Decimal = new Decimal(1).mul(0.5);
410console.info("test Decimal mul:" + data.toString()); // 'test Decimal mul:0.5'
411```
412
413### div
414
415div(n: Value): Decimal
416
417Returns a new **Decimal** object representing the quotient of dividing this decimal by the specified number *n*.
418
419You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
420
421**Atomic service API**: This API can be used in atomic services since API version 12.
422
423**System capability**: SystemCapability.Utils.Lang
424
425**Parameters**
426
427| Name| Type           | Mandatory| Description            |
428| ------ | --------------- | ---- | ---------------- |
429| n      | [Value](#value) | Yes  | Divisor.|
430
431**Return value**
432
433| Type   | Description                           |
434| ------- | ------------------------------- |
435| [Decimal](#decimal) | **Decimal** object representing the quotient.|
436
437**Error codes**
438
439For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
440
441| ID| Error Message                                                    |
442| -------- | ------------------------------------------------------------ |
443| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
444
445**Example**
446
447```ts
448let data: Decimal = new Decimal(1).div(0.5);
449console.info("test Decimal div:" + data.toString()); // 'test Decimal div:2'
450```
451
452### mod
453
454mod(n: Value): Decimal
455
456Returns a new **Decimal** object representing the remainder of dividing this decimal by the specified number *n*.
457
458You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
459
460**Atomic service API**: This API can be used in atomic services since API version 12.
461
462**System capability**: SystemCapability.Utils.Lang
463
464**Parameters**
465
466| Name| Type           | Mandatory| Description            |
467| ------ | --------------- | ---- | ---------------- |
468| n      | [Value](#value) | Yes  | Divisor.|
469
470**Return value**
471
472| Type   | Description                           |
473| ------- | ------------------------------- |
474| [Decimal](#decimal) | **Decimal** object representing the remainder.|
475
476**Error codes**
477
478For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
479
480| ID| Error Message                                                    |
481| -------- | ------------------------------------------------------------ |
482| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
483
484**Example**
485
486```ts
487let data: Decimal = new Decimal(2).mod(1);
488console.info("test Decimal mod:" + data.toString()); // 'test Decimal mod:0'
489```
490
491### sqrt
492
493sqrt(): Decimal
494
495Returns a new **Decimal** object representing the square root of this decimal.
496
497You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
498
499**Atomic service API**: This API can be used in atomic services since API version 12.
500
501**System capability**: SystemCapability.Utils.Lang
502
503**Return value**
504
505| Type   | Description                             |
506| ------- | --------------------------------- |
507| [Decimal](#decimal) | **Decimal** object representing the square root.|
508
509**Example**
510
511```ts
512let data: Decimal = new Decimal(3).sqrt();
513console.info("test Decimal sqrt:" + data.toString()); // 'test Decimal sqrt:1.7320508075688772935'
514```
515
516### cbrt
517
518cbrt(): Decimal
519
520Returns a new **Decimal** object representing the cube root of this decimal.
521
522You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
523
524**Atomic service API**: This API can be used in atomic services since API version 12.
525
526**System capability**: SystemCapability.Utils.Lang
527
528**Return value**
529
530| Type   | Description                             |
531| ------- | --------------------------------- |
532| [Decimal](#decimal) | **Decimal** object representing the cube root.|
533
534**Example**
535
536```ts
537let data: Decimal = new Decimal(3).cbrt();
538console.info("test Decimal cbrt:" + data.toString()); // 'test Decimal cbrt:1.4422495703074083823'
539```
540
541### pow
542
543pow(n: Value): Decimal
544
545Returns a new **Decimal** object representing the value resulting from raising this decimal to the power of the specified number *n*.
546
547You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
548
549**Atomic service API**: This API can be used in atomic services since API version 12.
550
551**System capability**: SystemCapability.Utils.Lang
552
553**Parameters**
554
555| Name| Type           | Mandatory| Description            |
556| ------ | --------------- | ---- | ---------------- |
557| n      | [Value](#value) | Yes  | Power of the exponentiation operation.|
558
559**Return value**
560
561| Type   | Description                         |
562| ------- | ----------------------------- |
563| [Decimal](#decimal) | **Decimal** object representing the result of the exponentiation operation.|
564
565**Error codes**
566
567For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Utils Error Codes](errorcode-utils.md).
568
569| ID| Error Message                                                    |
570| -------- | ------------------------------------------------------------ |
571| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
572| 10200060 | Precision limit exceeded.                                    |
573
574**Example**
575
576```ts
577let data: Decimal = new Decimal(3).pow(-2);
578console.info("test Decimal pow:" + data.toString()); // 'test Decimal pow:0.11111111111111111111'
579```
580
581### exp
582
583exp(): Decimal
584
585Returns a new **Decimal** object representing the value resulting from raising e to the power of this decimal.
586
587You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
588
589**Atomic service API**: This API can be used in atomic services since API version 12.
590
591**System capability**: SystemCapability.Utils.Lang
592
593**Return value**
594
595| Type               | Description                               |
596| ------------------- | ------------------------------------- |
597| [Decimal](#decimal) | **Decimal** object representing the result of the natural exponentiation operation.|
598
599**Error codes**
600
601For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
602
603| ID| Error Message                 |
604| -------- | ------------------------- |
605| 10200060 | Precision limit exceeded. |
606
607**Example**
608
609```ts
610let data: Decimal = new Decimal(2).exp();
611console.info("test Decimal exp:" + data.toString()); // 'test Decimal exp:7.3890560989306502272'
612```
613
614### log
615
616log(n: Value): Decimal
617
618Returns a new **Decimal** object representing the logarithm of this decimal to the specified base *n*.
619
620You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
621
622**Atomic service API**: This API can be used in atomic services since API version 12.
623
624**System capability**: SystemCapability.Utils.Lang
625
626**Parameters**
627
628| Name| Type           | Mandatory| Description              |
629| ------ | --------------- | ---- | ------------------ |
630| n      | [Value](#value) | Yes  | Base of the logarithm.|
631
632**Return value**
633
634| Type               | Description                             |
635| ------------------- | --------------------------------- |
636| [Decimal](#decimal) | **Decimal** object representing the logarithm.|
637
638**Error codes**
639
640For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Utils Error Codes](errorcode-utils.md).
641
642| ID| Error Message                                                    |
643| -------- | ------------------------------------------------------------ |
644| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
645| 10200060 | Precision limit exceeded.                                    |
646
647**Example**
648
649```ts
650let data: Decimal = new Decimal(2).log(256);
651console.info("test Decimal log:" + data.toString()); // 'test Decimal log:0.125'
652```
653
654### ln
655
656ln(): Decimal
657
658Returns a new **Decimal** object representing the natural logarithm of this decimal.
659
660You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
661
662**Atomic service API**: This API can be used in atomic services since API version 12.
663
664**System capability**: SystemCapability.Utils.Lang
665
666**Return value**
667
668| Type               | Description                                 |
669| ------------------- | ------------------------------------- |
670| [Decimal](#decimal) | **Decimal** object representing the natural logarithm.|
671
672**Error codes**
673
674For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
675
676| ID| Error Message                 |
677| -------- | ------------------------- |
678| 10200060 | Precision limit exceeded. |
679
680**Example**
681
682```ts
683let data: Decimal = new Decimal(1.23e+30).ln();
684console.info("test Decimal ln:" + data.toString()); // 'test Decimal ln:69.284566959205696648'
685```
686
687### cos
688
689cos(): Decimal
690
691Returns a new **Decimal** object representing the cosine of this decimal.
692
693**Atomic service API**: This API can be used in atomic services since API version 12.
694
695**System capability**: SystemCapability.Utils.Lang
696
697**Return value**
698
699| Type               | Description                             |
700| ------------------- | --------------------------------- |
701| [Decimal](#decimal) | **Decimal** object representing the cosine.|
702
703**Example**
704
705```ts
706let data: Decimal = new Decimal(-0.25).cos();
707console.info("test Decimal cos:" + data.toString()); // 'test Decimal cos:0.96891242171064478414'
708```
709
710### sin
711
712sin(): Decimal
713
714Returns a new **Decimal** object representing the sine of this decimal.
715
716**Atomic service API**: This API can be used in atomic services since API version 12.
717
718**System capability**: SystemCapability.Utils.Lang
719
720**Return value**
721
722| Type               | Description                             |
723| ------------------- | --------------------------------- |
724| [Decimal](#decimal) | **Decimal** object representing the sine.|
725
726**Example**
727
728```ts
729let data: Decimal = new Decimal(0.75).sin();
730console.info("test Decimal sin:" + data.toString()); // 'test Decimal sin:0.68163876002333416673'
731```
732
733### tan
734
735tan(): Decimal
736
737Returns a new **Decimal** object representing the tangent of this decimal.
738
739**Atomic service API**: This API can be used in atomic services since API version 12.
740
741**System capability**: SystemCapability.Utils.Lang
742
743**Return value**
744
745| Type               | Description                             |
746| ------------------- | --------------------------------- |
747| [Decimal](#decimal) | **Decimal** object representing the tangent.|
748
749**Example**
750
751```ts
752let data: Decimal = new Decimal(0.75).tan();
753console.info("test Decimal tan:" + data.toString()); // 'test Decimal tan:0.93159645994407246117'
754```
755
756### cosh
757
758cosh(): Decimal
759
760Returns a new **Decimal** object representing the hyperbolic cosine of this decimal.
761
762**Atomic service API**: This API can be used in atomic services since API version 12.
763
764**System capability**: SystemCapability.Utils.Lang
765
766**Return value**
767
768| Type   | Description                               |
769| ------- | ----------------------------------- |
770| [Decimal](#decimal) | **Decimal** object representing the hyperbolic cosine.|
771
772**Example**
773
774```ts
775let data: Decimal = new Decimal(0.5).cosh();
776console.info("test Decimal cosh:" + data.toString()); // 'test Decimal cosh:1.1276259652063807852'
777```
778
779### sinh
780
781sinh(): Decimal
782
783Returns a new **Decimal** object representing the hyperbolic sine of this decimal.
784
785**Atomic service API**: This API can be used in atomic services since API version 12.
786
787**System capability**: SystemCapability.Utils.Lang
788
789**Return value**
790
791| Type   | Description                               |
792| ------- | ----------------------------------- |
793| [Decimal](#decimal) | **Decimal** object representing the hyperbolic sine.|
794
795**Example**
796
797```ts
798let data: Decimal = new Decimal(0.5).sinh();
799console.info("test Decimal sinh:" + data.toString()); // 'test Decimal sinh:0.52109530549374736162'
800```
801
802### tanh
803
804tanh(): Decimal
805
806Returns a new **Decimal** object representing the hyperbolic tangent of this decimal.
807
808**Atomic service API**: This API can be used in atomic services since API version 12.
809
810**System capability**: SystemCapability.Utils.Lang
811
812**Return value**
813
814| Type   | Description                               |
815| ------- | ----------------------------------- |
816| [Decimal](#decimal) | **Decimal** object representing the hyperbolic tangent.|
817
818**Example**
819
820```ts
821let data: Decimal = new Decimal(0.5).tanh();
822console.info("test Decimal tanh:" + data.toString()); // 'test Decimal tanh:0.4621171572600097585'
823```
824
825### acos
826
827acos(): Decimal
828
829Returns a new **Decimal** object representing the arc cosine of this decimal.
830
831**Atomic service API**: This API can be used in atomic services since API version 12.
832
833**System capability**: SystemCapability.Utils.Lang
834
835**Return value**
836
837| Type   | Description                             |
838| ------- | --------------------------------- |
839| [Decimal](#decimal) | **Decimal** object representing the arc cosine.|
840
841**Error codes**
842
843For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
844
845| ID| Error Message                 |
846| -------- | ------------------------- |
847| 10200060 | Precision limit exceeded. |
848
849**Example**
850
851```ts
852let data: Decimal = new Decimal(0.5).acos();
853console.info("test Decimal acos:" + data.toString()); // 'test Decimal acos:1.0471975511965977462'
854```
855
856### asin
857
858asin(): Decimal
859
860Returns a new **Decimal** object representing the arc sine of this decimal.
861
862**Atomic service API**: This API can be used in atomic services since API version 12.
863
864**System capability**: SystemCapability.Utils.Lang
865
866**Return value**
867
868| Type   | Description                             |
869| ------- | --------------------------------- |
870| [Decimal](#decimal) | **Decimal** object representing the arc sine.|
871
872**Error codes**
873
874For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
875
876| ID| Error Message                 |
877| -------- | ------------------------- |
878| 10200060 | Precision limit exceeded. |
879
880**Example**
881
882```ts
883let data: Decimal = new Decimal(0.75).asin();
884console.info("test Decimal asin:" + data.toString()); // 'test Decimal asin:0.84806207898148100805'
885```
886
887### atan
888
889atan(): Decimal
890
891Returns a new **Decimal** object representing the arc tangent of this decimal.
892
893**Atomic service API**: This API can be used in atomic services since API version 12.
894
895**System capability**: SystemCapability.Utils.Lang
896
897**Return value**
898
899| Type   | Description                             |
900| ------- | --------------------------------- |
901| [Decimal](#decimal) | **Decimal** object representing the arc tangent.|
902
903**Error codes**
904
905For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
906
907| ID| Error Message                 |
908| -------- | ------------------------- |
909| 10200060 | Precision limit exceeded. |
910
911**Example**
912
913```ts
914let data: Decimal = new Decimal(0.75).atan();
915console.info("test Decimal atan:" + data.toString()); // 'test Decimal atan:0.6435011087932843868'
916```
917
918### acosh
919
920acosh(): Decimal
921
922Returns a new **Decimal** object representing the inverse hyperbolic cosine of this decimal.
923
924**Atomic service API**: This API can be used in atomic services since API version 12.
925
926**System capability**: SystemCapability.Utils.Lang
927
928**Return value**
929
930| Type               | Description                                       |
931| ------------------- | ------------------------------------------- |
932| [Decimal](#decimal) | **Decimal** object representing the inverse hyperbolic cosine.|
933
934**Error codes**
935
936For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
937
938| ID| Error Message                 |
939| -------- | ------------------------- |
940| 10200060 | Precision limit exceeded. |
941
942**Example**
943
944```ts
945let data: Decimal = new Decimal(50).acosh();
946console.info("test Decimal acosh:" + data.toString()); // 'test Decimal acosh:4.6050701709847571595'
947```
948
949### asinh
950
951asinh(): Decimal
952
953Returns a new **Decimal** object representing the inverse hyperbolic sine of this decimal.
954
955**Atomic service API**: This API can be used in atomic services since API version 12.
956
957**System capability**: SystemCapability.Utils.Lang
958
959**Return value**
960
961| Type               | Description                                       |
962| ------------------- | ------------------------------------------- |
963| [Decimal](#decimal) | **Decimal** object representing the inverse hyperbolic sine.|
964
965**Error codes**
966
967For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
968
969| ID| Error Message                 |
970| -------- | ------------------------- |
971| 10200060 | Precision limit exceeded. |
972
973**Example**
974
975```ts
976let data: Decimal = new Decimal(50).asinh();
977console.info("test Decimal asinh:" + data.toString()); // 'test Decimal asinh:4.6052701709914238266'
978```
979
980### atanh
981
982atanh(): Decimal
983
984Returns a new **Decimal** object representing the inverse hyperbolic tangent of this decimal.
985
986**Atomic service API**: This API can be used in atomic services since API version 12.
987
988**System capability**: SystemCapability.Utils.Lang
989
990**Return value**
991
992| Type               | Description                                       |
993| ------------------- | ------------------------------------------- |
994| [Decimal](#decimal) | **Decimal** object representing the inverse hyperbolic tangent.|
995
996**Error codes**
997
998For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
999
1000| ID| Error Message                 |
1001| -------- | ------------------------- |
1002| 10200060 | Precision limit exceeded. |
1003
1004**Example**
1005
1006```ts
1007let data: Decimal = new Decimal(0.75).atanh();
1008console.info("test Decimal atanh:" + data.toString()); // 'test Decimal atanh:0.97295507452765665255'
1009```
1010
1011### comparedTo
1012
1013comparedTo(n: Value): number
1014
1015Compares this decimal with the specified number *n*.
1016
1017**Atomic service API**: This API can be used in atomic services since API version 12.
1018
1019**System capability**: SystemCapability.Utils.Lang
1020
1021**Parameters**
1022
1023| Name| Type           | Mandatory| Description                 |
1024| ------ | --------------- | ---- | --------------------- |
1025| n      | [Value](#value) | Yes  | Target number to compare.|
1026
1027**Return value**
1028
1029| Type  | Description                                                        |
1030| ------ | ------------------------------------------------------------ |
1031| number | Comparison result, which can be any of the following:<br>**1**: The decimal is greater than *n*.<br>**-1**: The decimal is less than *n*.<br>**0**: The decimal is equal to *n*.<br>**NaN**: Either the decimal or *n* is Not a Number (NaN).|
1032
1033**Error codes**
1034
1035For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1036
1037| ID| Error Message                                                    |
1038| -------- | ------------------------------------------------------------ |
1039| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
1040
1041**Example**
1042
1043```ts
1044let data: Decimal = new Decimal(Infinity);
1045let data1: Decimal = new Decimal(5);
1046let data2: number = data.comparedTo(data1);
1047console.info("test Decimal comparedTo:" + data2); // 'test Decimal comparedTo:1'
1048
1049let data3: number = data1.comparedTo(10.5);
1050console.info("test Decimal comparedTo:" + data3); // 'test Decimal comparedTo:-1'
1051```
1052
1053### equals
1054
1055equals(n: Value): boolean
1056
1057Checks whether this decimal is equal to the specified number *n*.
1058
1059**Atomic service API**: This API can be used in atomic services since API version 12.
1060
1061**System capability**: SystemCapability.Utils.Lang
1062
1063**Parameters**
1064
1065| Name| Type           | Mandatory| Description                 |
1066| ------ | --------------- | ---- | --------------------- |
1067| n      | [Value](#value) | Yes  | Target number to compare.|
1068
1069**Return value**
1070
1071| Type   | Description                                            |
1072| ------- | ------------------------------------------------ |
1073| boolean | **true**: They are equal.<br>**false**: They are not equal.|
1074
1075**Error codes**
1076
1077For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1078
1079| ID| Error Message                                                    |
1080| -------- | ------------------------------------------------------------ |
1081| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
1082
1083**Example**
1084
1085```ts
1086let data: Decimal = new Decimal(0);
1087let data1: boolean = data.equals('1e-324');
1088console.info("test Decimal equals:" + data1); // 'test Decimal equals:false'
1089```
1090
1091### greaterThan
1092
1093greaterThan(n: Value): boolean
1094
1095Checks whether this decimal is greater than the specified number *n*.
1096
1097**Atomic service API**: This API can be used in atomic services since API version 12.
1098
1099**System capability**: SystemCapability.Utils.Lang
1100
1101**Parameters**
1102
1103| Name| Type           | Mandatory| Description                 |
1104| ------ | --------------- | ---- | --------------------- |
1105| n      | [Value](#value) | Yes  | Target number to compare.|
1106
1107**Return value**
1108
1109| Type   | Description                                          |
1110| ------- | ---------------------------------------------- |
1111| boolean | **true**: The decimal is greater than *n*.<br>**false**: The decimal is not greater than *n*.|
1112
1113**Error codes**
1114
1115For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1116
1117| ID| Error Message                                                    |
1118| -------- | ------------------------------------------------------------ |
1119| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
1120
1121**Example**
1122
1123```ts
1124let data: Decimal = new Decimal(0.1);
1125let data1: boolean = data.greaterThan(new Decimal(0.3).sub(0.2));
1126console.info("test Decimal greaterThan:" + data1); // 'test Decimal greaterThan:false'
1127```
1128
1129### greaterThanOrEqualTo
1130
1131greaterThanOrEqualTo(n: Value): boolean
1132
1133Checks whether this decimal is greater than or equal to the specified number *n*.
1134
1135**Atomic service API**: This API can be used in atomic services since API version 12.
1136
1137**System capability**: SystemCapability.Utils.Lang
1138
1139**Parameters**
1140
1141| Name| Type           | Mandatory| Description                 |
1142| ------ | --------------- | ---- | --------------------- |
1143| n      | [Value](#value) | Yes  | Target number to compare.|
1144
1145**Return value**
1146
1147| Type   | Description                                              |
1148| ------- | -------------------------------------------------- |
1149| boolean | **true**: The decimal is greater than or equal to *n*.<br>**false**: The decimal is not greater than or equal to *n*.|
1150
1151**Error codes**
1152
1153For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1154
1155| ID| Error Message                                                    |
1156| -------- | ------------------------------------------------------------ |
1157| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
1158
1159**Example**
1160
1161```ts
1162let data: Decimal = new Decimal(0.3).sub(0.2);
1163let data1: boolean = data.greaterThanOrEqualTo(0.1);
1164console.info("test Decimal greaterThanOrEqualTo:" + data1); // 'test Decimal greaterThanOrEqualTo:true'
1165```
1166
1167### lessThan
1168
1169lessThan(n: Value): boolean
1170
1171Checks whether this decimal is less than the specified number *n*.
1172
1173**Atomic service API**: This API can be used in atomic services since API version 12.
1174
1175**System capability**: SystemCapability.Utils.Lang
1176
1177**Parameters**
1178
1179| Name| Type           | Mandatory| Description                 |
1180| ------ | --------------- | ---- | --------------------- |
1181| n      | [Value](#value) | Yes  | Target number to compare.|
1182
1183**Return value**
1184
1185| Type   | Description                                          |
1186| ------- | ---------------------------------------------- |
1187| boolean | **true**: The decimal is less than *n*.<br>**false**: The decimal is not less than *n*.|
1188
1189**Error codes**
1190
1191For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1192
1193| ID| Error Message                                                    |
1194| -------- | ------------------------------------------------------------ |
1195| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
1196
1197**Example**
1198
1199```ts
1200let data: Decimal = new Decimal(0.3).sub(0.2);
1201let data1: boolean = data.lessThan(0.1)
1202console.info("test Decimal lessThan:" + data1); // 'test Decimal lessThan:false'
1203```
1204
1205### lessThanOrEqualTo
1206
1207lessThanOrEqualTo(n: Value): boolean
1208
1209Checks whether this decimal is less than or equal to the specified number *n*.
1210
1211**Atomic service API**: This API can be used in atomic services since API version 12.
1212
1213**System capability**: SystemCapability.Utils.Lang
1214
1215**Parameters**
1216
1217| Name| Type           | Mandatory| Description                 |
1218| ------ | --------------- | ---- | --------------------- |
1219| n      | [Value](#value) | Yes  | Target number to compare.|
1220
1221**Return value**
1222
1223| Type   | Description                                              |
1224| ------- | -------------------------------------------------- |
1225| boolean | **true**: The decimal is less than or equal to *n*.<br>**false**: The decimal is not less than or equal to *n*.|
1226
1227**Error codes**
1228
1229For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1230
1231| ID| Error Message                                                    |
1232| -------- | ------------------------------------------------------------ |
1233| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
1234
1235**Example**
1236
1237```ts
1238let data: Decimal = new Decimal(0.1);
1239let data1: boolean = data.lessThanOrEqualTo(new Decimal(0.3).sub(0.2))
1240console.info("test Decimal lessThanOrEqualTo:" + data1); // 'test Decimal lessThanOrEqualTo:true'
1241```
1242
1243### isFinite
1244
1245isFinite(): boolean
1246
1247Checks whether this decimal is finite.
1248
1249**Atomic service API**: This API can be used in atomic services since API version 12.
1250
1251**System capability**: SystemCapability.Utils.Lang
1252
1253**Return value**
1254
1255| Type   | Description                                        |
1256| ------- | -------------------------------------------- |
1257| boolean | **true**: The decimal is finite.<br>**false**: The decimal is not finite.|
1258
1259**Example**
1260
1261```ts
1262let data: Decimal = new Decimal(1);
1263let data1: boolean = data.isFinite();
1264console.info("test Decimal isFinite:" + data1); // 'test Decimal isFinite:true'
1265```
1266
1267### isInteger
1268
1269isInteger(): boolean
1270
1271Checks whether this decimal is an integer.
1272
1273**Atomic service API**: This API can be used in atomic services since API version 12.
1274
1275**System capability**: SystemCapability.Utils.Lang
1276
1277**Return value**
1278
1279| Type   | Description                                      |
1280| ------- | ------------------------------------------ |
1281| boolean | **true**: The decimal is an integer.<br>**false**: The decimal is not an integer.|
1282
1283**Example**
1284
1285```ts
1286let data: Decimal = new Decimal(123.456);
1287let data1: boolean = data.isInteger();
1288console.info("test Decimal isInteger:" + data1); // 'test Decimal isInteger:false'
1289```
1290
1291### isNaN
1292
1293isNaN(): boolean
1294
1295Checks whether this decimal is NaN.
1296
1297**Atomic service API**: This API can be used in atomic services since API version 12.
1298
1299**System capability**: SystemCapability.Utils.Lang
1300
1301**Return value**
1302
1303| Type   | Description                                     |
1304| ------- | ----------------------------------------- |
1305| boolean | **true**: The decimal is NaN.<br>**false**: The decimal is not NaN.|
1306
1307**Example**
1308
1309```ts
1310let data: Decimal = new Decimal(NaN);
1311let data1: boolean = data.isNaN();
1312console.info("test Decimal isNaN:" + data1); // 'test Decimal isNaN:true'
1313```
1314
1315### isNegative
1316
1317isNegative(): boolean
1318
1319Checks whether this decimal is negative.
1320
1321**Atomic service API**: This API can be used in atomic services since API version 12.
1322
1323**System capability**: SystemCapability.Utils.Lang
1324
1325**Return value**
1326
1327| Type   | Description                                      |
1328| ------- | ------------------------------------------ |
1329| boolean | **true**: The decimal is negative.<br>**false**: The decimal is not negative.|
1330
1331**Example**
1332
1333```ts
1334let data: Decimal = new Decimal(-5);
1335let data1: boolean = data.isNegative();
1336console.info("test Decimal isNegative:" + data1); // 'test Decimal isNegative:true'
1337
1338let data2: Decimal = new Decimal(-0);
1339let data3: boolean = data.isNegative();
1340console.info("test Decimal isNegative:" + data3); // 'test Decimal isNegative:true'
1341```
1342
1343### isPositive
1344
1345isPositive(): boolean
1346
1347Checks whether this decimal is positive.
1348
1349**Atomic service API**: This API can be used in atomic services since API version 12.
1350
1351**System capability**: SystemCapability.Utils.Lang
1352
1353**Return value**
1354
1355| Type   | Description                                      |
1356| ------- | ------------------------------------------ |
1357| boolean | **true**: The decimal is positive.<br>**false**: The decimal is not positive.|
1358
1359**Example**
1360
1361```ts
1362let data: Decimal = new Decimal(5);
1363let data1: boolean = data.isPositive();
1364console.info("test Decimal isPositive:" + data1); // 'test Decimal isPositive:true'
1365
1366let data2: Decimal = new Decimal(0);
1367let data3: boolean = data.isPositive();
1368console.info("test Decimal isPositive:" + data3); // 'test Decimal isPositive:true'
1369```
1370
1371### isZero
1372
1373isZero(): boolean
1374
1375Returns whether this decimal is zero or minus zero.
1376
1377**Atomic service API**: This API can be used in atomic services since API version 12.
1378
1379**System capability**: SystemCapability.Utils.Lang
1380
1381**Return value**
1382
1383| Type   | Description                                         |
1384| ------- | --------------------------------------------- |
1385| boolean | **true**: The decimal is zero or minus zero.<br>**false**: The decimal is not zero.|
1386
1387**Example**
1388
1389```ts
1390let data: Decimal = new Decimal(0);
1391let data1: boolean = data.isZero();
1392console.info("test Decimal isZero:" + data1.toString()); // 'test Decimal isZero:true'
1393```
1394
1395### dividedToIntegerBy
1396
1397dividedToIntegerBy(n: Value): Decimal
1398
1399Returns a new **Decimal** object representing the integer part of this decimal divided by the specified number *n*.
1400
1401You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
1402
1403**Atomic service API**: This API can be used in atomic services since API version 12.
1404
1405**System capability**: SystemCapability.Utils.Lang
1406
1407**Parameters**
1408
1409| Name| Type           | Mandatory| Description          |
1410| ------ | --------------- | ---- | -------------- |
1411| n      | [Value](#value) | Yes  | Divisor.|
1412
1413**Return value**
1414
1415| Type               | Description                                                        |
1416| ------------------- | ------------------------------------------------------------ |
1417| [Decimal](#decimal) | **Decimal** object representing the integer part.|
1418
1419**Error codes**
1420
1421For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
1422
1423| ID| Error Message                                                    |
1424| -------- | ------------------------------------------------------------ |
1425| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
1426
1427**Example**
1428
1429```ts
1430let data: Decimal = new Decimal(5);
1431let data1: Decimal = new Decimal(3);
1432let data2: Decimal = data.dividedToIntegerBy(data1);
1433console.info("test Decimal dividedToIntegerBy:" + data2.toString()); // 'test Decimal dividedToIntegerBy:1'
1434```
1435
1436### negate
1437
1438negate(): Decimal
1439
1440Returns a new **Decimal** object representing the result of multiplying this decimal by negative one.
1441
1442**Atomic service API**: This API can be used in atomic services since API version 12.
1443
1444**System capability**: SystemCapability.Utils.Lang
1445
1446**Return value**
1447
1448| Type               | Description                                            |
1449| ------------------- | ------------------------------------------------ |
1450| [Decimal](#decimal) | **Decimal** object representing the negated value of the decimal.|
1451
1452**Example**
1453
1454```ts
1455let data: Decimal = new Decimal(1.8);
1456let data1: Decimal = data.negate();
1457console.info("test Decimal negate:" + data1.toString()); // 'test Decimal negate:-1.8'
1458```
1459
1460### toBinary
1461
1462toBinary(): string
1463
1464Converts this decimal into a binary string.
1465
1466You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
1467
1468**Atomic service API**: This API can be used in atomic services since API version 12.
1469
1470**System capability**: SystemCapability.Utils.Lang
1471
1472**Return value**
1473
1474| Type  | Description                    |
1475| ------ | ------------------------ |
1476| string | Binary string.|
1477
1478**Error codes**
1479
1480For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
1481
1482| ID| Error Message                                         |
1483| -------- | ------------------------------------------------- |
1484| 10200001 | The value of 'significantDigits' is out of range. |
1485
1486**Example**
1487
1488```ts
1489let data: Decimal = new Decimal(256);
1490let data1: string = data.toBinary();
1491console.info("test Decimal toBinary:" + data1); // 'test Decimal toBinary:0b100000000'
1492```
1493
1494### toBinary
1495
1496toBinary(significantDigits: number): string
1497
1498Converts this decimal into a binary string, with the number of significant digits specified.
1499
1500You can use [DecimalConfig.rounding](#decimalconfig) to set the rounding mode.
1501
1502**Atomic service API**: This API can be used in atomic services since API version 12.
1503
1504**System capability**: SystemCapability.Utils.Lang
1505
1506**Parameters**
1507
1508| Name           | Type  | Mandatory| Description                                            |
1509| ----------------- | ------ | ---- | ------------------------------------------------ |
1510| significantDigits | number | Yes  | Number of significant digits to reserve. The value is an integer in the range of [1, 1e9].|
1511
1512**Return value**
1513
1514| Type  | Description                    |
1515| ------ | ------------------------ |
1516| string | Binary string.|
1517
1518**Error codes**
1519
1520For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
1521
1522| ID| Error Message                                         |
1523| -------- | ------------------------------------------------- |
1524| 10200001 | The value of 'significantDigits' is out of range. |
1525
1526**Example**
1527
1528```ts
1529let data: Decimal = new Decimal(256);
1530let data1: string = data.toBinary(1);
1531console.info("test Decimal toBinary:" + data1); // 'test Decimal toBinary:0b1p+8'
1532```
1533
1534### toBinary
1535
1536toBinary(significantDigits: number, rounding: Rounding): string
1537
1538Converts this decimal into a binary string, with the number of significant digits and rounding mode specified.
1539
1540**Atomic service API**: This API can be used in atomic services since API version 12.
1541
1542**System capability**: SystemCapability.Utils.Lang
1543
1544**Parameters**
1545
1546| Name           | Type                 | Mandatory| Description                                                     |
1547| ----------------- | --------------------- | ---- | --------------------------------------------------------- |
1548| significantDigits | number                | Yes  | Number of significant digits to reserve. The value is an integer in the range of [1, 1e9].         |
1549| rounding          | [Rounding](#rounding) | Yes  | Rounding mode. For details, see [Rounding](#rounding).|
1550
1551**Return value**
1552
1553| Type  | Description                    |
1554| ------ | ------------------------ |
1555| string | Binary string.|
1556
1557**Error codes**
1558
1559For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
1560
1561| ID| Error Message                                                    |
1562| -------- | ------------------------------------------------------------ |
1563| 10200001 | The value of 'significantDigits \| rounding' is out of range. |
1564
1565**Example**
1566
1567```ts
1568let data: Decimal = new Decimal(256);
1569let data1: string = data.toBinary(1, Decimal.ROUND_HALF_UP);
1570console.info("test Decimal toBinary:" + data1); // 'test Decimal toBinary:0b1p+8'
1571```
1572
1573### toOctal
1574
1575toOctal(): string
1576
1577Converts this decimal into an octal string.
1578
1579You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
1580
1581**Atomic service API**: This API can be used in atomic services since API version 12.
1582
1583**System capability**: SystemCapability.Utils.Lang
1584
1585**Return value**
1586
1587| Type  | Description                    |
1588| ------ | ------------------------ |
1589| string | Octal string.|
1590
1591**Example**
1592
1593```ts
1594let data: Decimal = new Decimal(256);
1595let data1: string = data.toOctal();
1596console.info("test Decimal toOctal:" + data1); // 'test Decimal toOctal:0o400'
1597```
1598
1599### toOctal
1600
1601toOctal(significantDigits: number): string
1602
1603Converts this decimal into an octal string, with the number of significant digits specified.
1604
1605You can use [DecimalConfig.rounding](#decimalconfig) to set the rounding mode.
1606
1607**Atomic service API**: This API can be used in atomic services since API version 12.
1608
1609**System capability**: SystemCapability.Utils.Lang
1610
1611**Parameters**
1612
1613| Name           | Type  | Mandatory| Description                                            |
1614| ----------------- | ------ | ---- | ------------------------------------------------ |
1615| significantDigits | number | Yes  | Number of significant digits to reserve. The value is an integer in the range of [1, 1e9].|
1616
1617**Return value**
1618
1619| Type  | Description                    |
1620| ------ | ------------------------ |
1621| string | Octal string.|
1622
1623**Error codes**
1624
1625For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
1626
1627| ID| Error Message                                         |
1628| -------- | ------------------------------------------------- |
1629| 10200001 | The value of 'significantDigits' is out of range. |
1630
1631**Example**
1632
1633```ts
1634let data: Decimal = new Decimal(256);
1635let data1: string = data.toOctal(1);
1636console.info("test Decimal toOctal:" + data1); // 'test Decimal toOctal:0o1p+8'
1637```
1638
1639### toOctal
1640
1641toOctal(significantDigits: number, rounding: Rounding): string
1642
1643Converts this decimal into an octal string, with the number of significant digits and rounding mode specified.
1644
1645**Atomic service API**: This API can be used in atomic services since API version 12.
1646
1647**System capability**: SystemCapability.Utils.Lang
1648
1649**Parameters**
1650
1651| Name           | Type                 | Mandatory| Description                                                     |
1652| ----------------- | --------------------- | ---- | --------------------------------------------------------- |
1653| significantDigits | number                | Yes  | Number of significant digits to reserve. The value is an integer in the range of [1, 1e9].         |
1654| rounding          | [Rounding](#rounding) | Yes  | Rounding mode. For details, see [Rounding](#rounding).|
1655
1656**Return value**
1657
1658| Type  | Description                    |
1659| ------ | ------------------------ |
1660| string | Octal string.|
1661
1662**Error codes**
1663
1664For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
1665
1666| ID| Error Message                                                    |
1667| -------- | ------------------------------------------------------------ |
1668| 10200001 | The value of 'significantDigits \| rounding' is out of range. |
1669
1670**Example**
1671
1672```ts
1673let data: Decimal = new Decimal(256);
1674let data1: string = data.toOctal(1, Decimal.ROUND_HALF_UP);
1675console.info("test Decimal toOctal:" + data1); // 'test Decimal toOctal:0o1p+8'
1676```
1677
1678### toHexadecimal
1679
1680toHexadecimal(): string
1681
1682Converts this decimal into a hexadecimal string.
1683
1684You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
1685
1686**Atomic service API**: This API can be used in atomic services since API version 12.
1687
1688**System capability**: SystemCapability.Utils.Lang
1689
1690**Return value**
1691
1692| Type  | Description                      |
1693| ------ | -------------------------- |
1694| string | Hexadecimal string.|
1695
1696**Example**
1697
1698```ts
1699let data: Decimal = new Decimal(256);
1700let data1: string = data.toHexadecimal();
1701console.info("test Decimal toHexadecimal:" + data1); // 'test Decimal toHexadecimal:0x100'
1702```
1703
1704### toHexadecimal
1705
1706toHexadecimal(significantDigits: number): string
1707
1708Converts this decimal into a hexadecimal string, with the number of significant digits specified.
1709
1710You can use [DecimalConfig.rounding](#decimalconfig) to set the rounding mode.
1711
1712**Atomic service API**: This API can be used in atomic services since API version 12.
1713
1714**System capability**: SystemCapability.Utils.Lang
1715
1716**Parameters**
1717
1718| Name           | Type  | Mandatory| Description                                            |
1719| ----------------- | ------ | ---- | ------------------------------------------------ |
1720| significantDigits | number | Yes  | Number of significant digits to reserve. The value is an integer in the range of [1, 1e9].|
1721
1722**Return value**
1723
1724| Type  | Description                      |
1725| ------ | -------------------------- |
1726| string | Hexadecimal string.|
1727
1728**Error codes**
1729
1730For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
1731
1732| ID| Error Message                                         |
1733| -------- | ------------------------------------------------- |
1734| 10200001 | The value of 'significantDigits' is out of range. |
1735
1736**Example**
1737
1738```ts
1739let data: Decimal = new Decimal(256);
1740let data1: string = data.toHexadecimal(1);
1741console.info("test Decimal toHexadecimal:" + data1); // 'test Decimal toHexadecimal:0x1p+8'
1742```
1743
1744### toHexadecimal
1745
1746toHexadecimal(significantDigits: number, rounding: Rounding): string
1747
1748Converts this decimal into a hexadecimal string, with the number of significant digits and rounding mode specified.
1749
1750**Atomic service API**: This API can be used in atomic services since API version 12.
1751
1752**System capability**: SystemCapability.Utils.Lang
1753
1754**Parameters**
1755
1756| Name           | Type                 | Mandatory| Description                                                     |
1757| ----------------- | --------------------- | ---- | --------------------------------------------------------- |
1758| significantDigits | number                | Yes  | Number of significant digits to reserve. The value is an integer in the range of [1, 1e9].         |
1759| rounding          | [Rounding](#rounding) | Yes  | Rounding mode. For details, see [Rounding](#rounding).|
1760
1761**Return value**
1762
1763| Type  | Description                      |
1764| ------ | -------------------------- |
1765| string | Hexadecimal string.|
1766
1767**Error codes**
1768
1769For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
1770
1771| ID| Error Message                                                    |
1772| -------- | ------------------------------------------------------------ |
1773| 10200001 | The value of 'significantDigits \| rounding' is out of range. |
1774
1775**Example**
1776
1777```ts
1778let data: Decimal = new Decimal(256);
1779let data1: string = data.toHexadecimal(1, Decimal.ROUND_HALF_UP);
1780console.info("test Decimal toHexadecimal:" + data1); // 'test Decimal toHexadecimal:0x1p+8'
1781```
1782
1783### toDecimalPlaces
1784
1785toDecimalPlaces(): Decimal
1786
1787Truncates this decimal, without rounding.
1788
1789**Atomic service API**: This API can be used in atomic services since API version 12.
1790
1791**System capability**: SystemCapability.Utils.Lang
1792
1793**Return value**
1794
1795| Type               | Description                                       |
1796| ------------------- | ------------------------------------------- |
1797| [Decimal](#decimal) | **Decimal** object presenting the value with the given number of decimal places.|
1798
1799**Example**
1800
1801```ts
1802let data: Decimal = new Decimal(12.34567);
1803let data1: Decimal = data.toDecimalPlaces();
1804console.info("test Decimal toDecimalPlaces:" + data1.toString()); // 'test Decimal toDecimalPlaces:12.34567'
1805```
1806
1807### toDecimalPlaces
1808
1809toDecimalPlaces(decimalPlaces: number): Decimal
1810
1811Truncates this decimal to a given number of decimal places.
1812
1813You can use [DecimalConfig.rounding](#decimalconfig) to set the rounding mode.
1814
1815**Atomic service API**: This API can be used in atomic services since API version 12.
1816
1817**System capability**: SystemCapability.Utils.Lang
1818
1819**Parameters**
1820
1821| Name       | Type  | Mandatory| Description                                                    |
1822| ------------- | ------ | ---- | -------------------------------------------------------- |
1823| decimalPlaces | number | Yes  | Number of decimal places to reserve. The value is an integer in the range of [0, 1e9].|
1824
1825**Return value**
1826
1827| Type               | Description                                       |
1828| ------------------- | ------------------------------------------- |
1829| [Decimal](#decimal) | **Decimal** object presenting the value with the given number of decimal places.|
1830
1831**Error codes**
1832
1833For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
1834
1835| ID| Error Message                                     |
1836| -------- | --------------------------------------------- |
1837| 10200001 | The value of 'decimalPlaces' is out of range. |
1838
1839**Example**
1840
1841```ts
1842let data: Decimal = new Decimal(9876.54321);
1843let data1: Decimal = data.toDecimalPlaces(3);
1844console.info("test Decimal toDecimalPlaces:" + data1.toString()); // 'test Decimal toDecimalPlaces:9876.543'
1845```
1846
1847### toDecimalPlaces
1848
1849toDecimalPlaces(decimalPlaces: number, rounding: Rounding): Decimal
1850
1851Truncates this decimal to a given number of decimal places, with the rounding mode specified.
1852
1853**Atomic service API**: This API can be used in atomic services since API version 12.
1854
1855**System capability**: SystemCapability.Utils.Lang
1856
1857**Parameters**
1858
1859| Name       | Type                 | Mandatory| Description                                                     |
1860| ------------- | --------------------- | ---- | --------------------------------------------------------- |
1861| decimalPlaces | number                | Yes  | Number of decimal places to reserve. The value is an integer in the range of [0, 1e9]. |
1862| rounding      | [Rounding](#rounding) | Yes  | Rounding mode. For details, see [Rounding](#rounding).|
1863
1864**Return value**
1865
1866| Type               | Description                                       |
1867| ------------------- | ------------------------------------------- |
1868| [Decimal](#decimal) | **Decimal** object presenting the value with the given number of decimal places.|
1869
1870**Error codes**
1871
1872For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
1873
1874| ID| Error Message                                                 |
1875| -------- | --------------------------------------------------------- |
1876| 10200001 | The value of 'decimalPlaces \| rounding' is out of range. |
1877
1878**Example**
1879
1880```ts
1881let data: Decimal = new Decimal(9876.54321);
1882let data1: Decimal = data.toDecimalPlaces(1, 0);
1883console.info("test Decimal toDecimalPlaces:" + data1.toString()); // 'test Decimal toDecimalPlaces:9876.6'
1884data1 = data.toDecimalPlaces(1, Decimal.ROUND_DOWN) // data1: '9876.5'
1885```
1886
1887### toExponential
1888
1889toExponential(): string
1890
1891Converts this decimal to a string expressed in exponential notation, without rounding.
1892
1893**Atomic service API**: This API can be used in atomic services since API version 12.
1894
1895**System capability**: SystemCapability.Utils.Lang
1896
1897**Return value**
1898
1899| Type  | Description                            |
1900| ------ | -------------------------------- |
1901| string | String expressed in exponential notation.|
1902
1903**Example**
1904
1905```ts
1906let data: Decimal = new Decimal(45.6);
1907let data1: string = data.toExponential();
1908console.info("test Decimal toExponential:" + data1); // 'test Decimal toExponential:4.56e+1'
1909```
1910
1911### toExponential
1912
1913toExponential(decimalPlaces: number): string
1914
1915Converts this decimal to a string expressed in exponential notation, with the number of decimal places specified.
1916
1917You can use [DecimalConfig.rounding](#decimalconfig) to set the rounding mode.
1918
1919**Atomic service API**: This API can be used in atomic services since API version 12.
1920
1921**System capability**: SystemCapability.Utils.Lang
1922
1923**Parameters**
1924
1925| Name       | Type  | Mandatory| Description                                                    |
1926| ------------- | ------ | ---- | -------------------------------------------------------- |
1927| decimalPlaces | number | Yes  | Number of decimal places to reserve. The value is an integer in the range of [0, 1e9].|
1928
1929**Return value**
1930
1931| Type  | Description                            |
1932| ------ | -------------------------------- |
1933| string | String expressed in exponential notation.|
1934
1935**Error codes**
1936
1937For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
1938
1939| ID| Error Message                                     |
1940| -------- | --------------------------------------------- |
1941| 10200001 | The value of 'decimalPlaces' is out of range. |
1942
1943**Example**
1944
1945```ts
1946let data: Decimal = new Decimal(45.6);
1947let data1: string = data.toExponential(0);
1948console.info("test Decimal toExponential:" + data1); // 'test Decimal toExponential:5e+1'
1949data1 = data.toExponential(1) // data1: '4.6e+1'
1950data1 = data.toExponential(3) // data1: '4.560e+1'
1951```
1952
1953### toExponential
1954
1955toExponential(decimalPlaces: number, rounding: Rounding): string
1956
1957Converts this decimal to a string expressed in exponential notation, with the number of decimal places and rounding mode specified.
1958
1959**Atomic service API**: This API can be used in atomic services since API version 12.
1960
1961**System capability**: SystemCapability.Utils.Lang
1962
1963**Parameters**
1964
1965| Name       | Type                 | Mandatory| Description                                                     |
1966| ------------- | --------------------- | ---- | --------------------------------------------------------- |
1967| decimalPlaces | number                | Yes  | Number of decimal places to reserve. The value is an integer in the range of [0, 1e9]. |
1968| rounding      | [Rounding](#rounding) | Yes  | Rounding mode. For details, see [Rounding](#rounding).|
1969
1970**Return value**
1971
1972| Type  | Description                            |
1973| ------ | -------------------------------- |
1974| string | String expressed in exponential notation.|
1975
1976**Error codes**
1977
1978For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
1979
1980| ID| Error Message                                                 |
1981| -------- | --------------------------------------------------------- |
1982| 10200001 | The value of 'decimalPlaces \| rounding' is out of range. |
1983
1984**Example**
1985
1986```ts
1987let data: Decimal = new Decimal(45.6);
1988let data1 = data.toExponential(1, Decimal.ROUND_DOWN)
1989console.info("test Decimal toExponential:" + data1); // 'test Decimal toExponential:4.5e+1'
1990```
1991
1992### toFixed
1993
1994toFixed(): string
1995
1996Converts this decimal to a string expressed in decimal fixed-point mode, without rounding.
1997
1998**Atomic service API**: This API can be used in atomic services since API version 12.
1999
2000**System capability**: SystemCapability.Utils.Lang
2001
2002**Return value**
2003
2004| Type               | Description                                            |
2005| ------------------- | ------------------------------------------------ |
2006| [Decimal](#decimal) | String expressed in decimal fixed-point mode.|
2007
2008**Example**
2009
2010```ts
2011let data: Decimal = new Decimal(3.456);
2012let data1: string = data.toFixed();
2013console.info("test Decimal toFixed:" + data1); // 'test Decimal toFixed:3.456'
2014```
2015
2016### toFixed
2017
2018toFixed(decimalPlaces: number): string
2019
2020Converts this decimal to a string expressed in decimal fixed-point mode, with the number of decimal places specified.
2021
2022You can use [DecimalConfig.rounding](#decimalconfig) to set the rounding mode.
2023
2024**Atomic service API**: This API can be used in atomic services since API version 12.
2025
2026**System capability**: SystemCapability.Utils.Lang
2027
2028**Parameters**
2029
2030| Name       | Type  | Mandatory| Description                                                    |
2031| ------------- | ------ | ---- | -------------------------------------------------------- |
2032| decimalPlaces | number | Yes  | Number of decimal places to reserve. The value is an integer in the range of [0, 1e9].|
2033
2034**Return value**
2035
2036| Type               | Description                                            |
2037| ------------------- | ------------------------------------------------ |
2038| [Decimal](#decimal) | String expressed in decimal fixed-point mode.|
2039
2040**Error codes**
2041
2042For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
2043
2044| ID| Error Message                                     |
2045| -------- | --------------------------------------------- |
2046| 10200001 | The value of 'decimalPlaces' is out of range. |
2047
2048**Example**
2049
2050```ts
2051let data: Decimal = new Decimal(3.456);
2052let data1: string = data.toFixed(0)
2053console.info("test Decimal toFixed:" + data1); // 'test Decimal toFixed:3'
2054data1 = data.toFixed(2) // data1: '3.46'
2055data1 = data.toFixed(5) // data1: '3.45600'
2056```
2057
2058### toFixed
2059
2060toFixed(decimalPlaces: number, rounding: Rounding): string
2061
2062Converts this decimal to a string expressed in decimal fixed-point mode, with the number of decimal places and rounding mode specified.
2063
2064**Atomic service API**: This API can be used in atomic services since API version 12.
2065
2066**System capability**: SystemCapability.Utils.Lang
2067
2068**Parameters**
2069
2070| Name       | Type                 | Mandatory| Description                                                     |
2071| ------------- | --------------------- | ---- | --------------------------------------------------------- |
2072| decimalPlaces | number                | Yes  | Number of decimal places to reserve. The value is an integer in the range of [0, 1e9]. |
2073| rounding      | [Rounding](#rounding) | Yes  | Rounding mode. For details, see [Rounding](#rounding).|
2074
2075**Return value**
2076
2077| Type               | Description                                            |
2078| ------------------- | ------------------------------------------------ |
2079| [Decimal](#decimal) | String expressed in decimal fixed-point mode.|
2080
2081**Error codes**
2082
2083For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
2084
2085| ID| Error Message                                                 |
2086| -------- | --------------------------------------------------------- |
2087| 10200001 | The value of 'decimalPlaces \| rounding' is out of range. |
2088
2089**Example**
2090
2091```ts
2092let data: Decimal = new Decimal(3.456);
2093let data1: string = data.toFixed(2, Decimal.ROUND_DOWN);
2094console.info("test Decimal toFixed:" + data1); // b: 'test Decimal toFixed:3.45'
2095```
2096
2097### toFraction
2098
2099toFraction(): Decimal[]
2100
2101Converts this decimal into a fraction.
2102
2103**Atomic service API**: This API can be used in atomic services since API version 12.
2104
2105**System capability**: SystemCapability.Utils.Lang
2106
2107**Return value**
2108
2109| Type                 | Description                                                        |
2110| --------------------- | ------------------------------------------------------------ |
2111| [Decimal](#decimal)[] | Decimal array with a fixed length of 2. The two integers in the array represent the numerator and the denominator, respectively.|
2112
2113**Example**
2114
2115```ts
2116let data: Decimal = new Decimal(1.75);
2117let data1: Decimal[] = data.toFraction();
2118console.info("test Decimal toFraction:" + data1.toString()); // 'test Decimal toFraction:7,4'
2119```
2120
2121### toFraction
2122
2123toFraction(max_denominator: Value): Decimal[]
2124
2125Converts this decimal to a fraction, with the maximum denominator specified.
2126
2127**Atomic service API**: This API can be used in atomic services since API version 12.
2128
2129**System capability**: SystemCapability.Utils.Lang
2130
2131**Parameters**
2132
2133| Name         | Type           | Mandatory| Description                    |
2134| --------------- | --------------- | ---- | ------------------------ |
2135| max_denominator | [Value](#value) | Yes  | Maximum denominator. This value is inclusive.|
2136
2137**Return value**
2138
2139| Type                 | Description                                                        |
2140| --------------------- | ------------------------------------------------------------ |
2141| [Decimal](#decimal)[] | Decimal array with a fixed length of 2. The two integers in the array represent the numerator and the denominator, respectively.|
2142
2143**Error codes**
2144
2145For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2146
2147| ID| Error Message                                                    |
2148| -------- | ------------------------------------------------------------ |
2149| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
2150
2151**Example**
2152
2153```ts
2154let pi: Decimal = new Decimal('3.14159265358')
2155let data1 = pi.toFraction() // data1: '157079632679,50000000000'
2156data1 = pi.toFraction(100000) // data1: '312689, 99532'
2157data1 = pi.toFraction(10000) // data1: '355, 113'
2158data1 = pi.toFraction(100) // data1: '311, 99'
2159data1 = pi.toFraction(10) // data1: '22, 7'
2160data1 = pi.toFraction(1) // data1: '3, 1'
2161```
2162
2163### toNearest
2164
2165toNearest(n: Value): Decimal
2166
2167Multiplies the specified number *n* to a value closet to this decimal and returns this closest value in the form of a **Decimal object**.
2168
2169**Atomic service API**: This API can be used in atomic services since API version 12.
2170
2171**System capability**: SystemCapability.Utils.Lang
2172
2173**Parameters**
2174
2175| Name| Type           | Mandatory| Description          |
2176| ------ | --------------- | ---- | -------------- |
2177| n      | [Value](#value) | Yes  | Number to be multiplied.|
2178
2179**Return value**
2180
2181| Type   | Description                                       |
2182| ------- | ------------------------------------------- |
2183| Decimal | **Decimal** object representing the closest value.|
2184
2185**Error codes**
2186
2187For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
2188
2189| ID| Error Message                                |
2190| -------- | ---------------------------------------- |
2191| 10200001 | The value of 'rounding' is out of range. |
2192
2193**Example**
2194
2195```ts
2196let data: Decimal = new Decimal(1.39);
2197let data1: Decimal = data.toNearest(0.25);
2198console.info("test Decimal toNearest:" + data1.toString()); // 'test Decimal toNearest:1.5'
2199```
2200
2201### toNearest
2202
2203toNearest(n: Value, rounding: Rounding): Decimal
2204
2205Multiplies the specified number *n* to a value closet to this decimal and returns this closest value after rounding in the form of a **Decimal** object.
2206
2207**Atomic service API**: This API can be used in atomic services since API version 12.
2208
2209**System capability**: SystemCapability.Utils.Lang
2210
2211**Parameters**
2212
2213| Name  | Type                 | Mandatory| Description                                                     |
2214| -------- | --------------------- | ---- | --------------------------------------------------------- |
2215| n        | [Value](#value)       | Yes  | Number to be multiplied.                                           |
2216| rounding | [Rounding](#rounding) | Yes  | Rounding mode. For details, see [Rounding](#rounding).|
2217
2218**Return value**
2219
2220| Type               | Description                                       |
2221| ------------------- | ------------------------------------------- |
2222| [Decimal](#decimal) | **Decimal** object representing the closest value.|
2223
2224**Error codes**
2225
2226For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
2227
2228| ID| Error Message                                |
2229| -------- | ---------------------------------------- |
2230| 10200001 | The value of 'rounding' is out of range. |
2231
2232**Example**
2233
2234```ts
2235let data: Decimal = new Decimal(9.499)
2236let data1 = data.toNearest(0.5, Decimal.ROUND_UP) // data1: '9.5'
2237data1 = data.toNearest(0.5, Decimal.ROUND_DOWN) // data1: '9'
2238```
2239
2240### toPrecision
2241
2242toPrecision(): string
2243
2244Converts this decimal into a string.
2245
2246You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
2247
2248**Atomic service API**: This API can be used in atomic services since API version 12.
2249
2250**System capability**: SystemCapability.Utils.Lang
2251
2252**Return value**
2253
2254| Type  | Description                             |
2255| ------ | --------------------------------- |
2256| string | **Decimal** object representing the string.|
2257
2258**Example**
2259
2260```ts
2261let data: Decimal = new Decimal(45.6);
2262let data1: string = data.toPrecision();
2263console.info("test Decimal toPrecision:" + data1); // 'test Decimal toPrecision:45.6'
2264```
2265
2266### toPrecision
2267
2268toPrecision(significantDigits: number): string
2269
2270Converts this decimal into a string, with the number of significant digits specified.
2271
2272You can use [DecimalConfig.rounding](#decimalconfig) to set the rounding mode.
2273
2274**Atomic service API**: This API can be used in atomic services since API version 12.
2275
2276**System capability**: SystemCapability.Utils.Lang
2277
2278**Parameters**
2279
2280| Name           | Type  | Mandatory| Description                  |
2281| ----------------- | ------ | ---- | ---------------------- |
2282| significantDigits | number | Yes  | Number of significant digits to reserve.|
2283
2284**Return value**
2285
2286| Type  | Description                             |
2287| ------ | --------------------------------- |
2288| string | **Decimal** object representing the string.|
2289
2290**Error codes**
2291
2292For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
2293
2294| ID| Error Message                                         |
2295| -------- | ------------------------------------------------- |
2296| 10200001 | The value of 'significantDigits' is out of range. |
2297
2298**Example**
2299
2300```ts
2301let data: Decimal = new Decimal(45.6);
2302let data1: string = data.toPrecision(1);
2303console.info("test Decimal toPrecision:" + data1); // 'test Decimal toPrecision:5e+1'
2304data1 = data.toPrecision(5); // data1: '45.600'
2305```
2306
2307### toPrecision
2308
2309toPrecision(significantDigits: number, rounding: Rounding): string
2310
2311Converts this decimal into a string, with the number of significant digits and rounding mode specified.
2312
2313**Atomic service API**: This API can be used in atomic services since API version 12.
2314
2315**System capability**: SystemCapability.Utils.Lang
2316
2317**Parameters**
2318
2319| Name           | Type                 | Mandatory| Description                                                     |
2320| ----------------- | --------------------- | ---- | --------------------------------------------------------- |
2321| significantDigits | number                | Yes  | Number of significant digits to reserve. The value is an integer in the range of [1, 1e9].         |
2322| rounding          | [Rounding](#rounding) | Yes  | Rounding mode. For details, see [Rounding](#rounding).|
2323
2324**Return value**
2325
2326| Type  | Description                             |
2327| ------ | --------------------------------- |
2328| string | **Decimal** object representing the string.|
2329
2330**Error codes**
2331
2332For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
2333
2334| ID| Error Message                                                    |
2335| -------- | ------------------------------------------------------------ |
2336| 10200001 | The value of 'significantDigits \|  rounding' is out of range. |
2337
2338**Example**
2339
2340```ts
2341let data: Decimal = new Decimal(45.6);
2342let data1: string = data.toPrecision(2, Decimal.ROUND_UP) // data1: '46'
2343data1 = data.toPrecision(2, Decimal.ROUND_DOWN) // data1: '45'
2344```
2345
2346### toSignificantDigits
2347
2348toSignificantDigits(): Decimal
2349
2350Converts this decimal into another one with the number of significant digits specified.
2351
2352You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
2353
2354**Atomic service API**: This API can be used in atomic services since API version 12.
2355
2356**System capability**: SystemCapability.Utils.Lang
2357
2358**Return value**
2359
2360| Type   | Description                                   |
2361| ------- | --------------------------------------- |
2362| [Decimal](#decimal) | **Decimal** object with the specified number of significant digits.|
2363
2364**Example**
2365
2366```ts
2367let data: Decimal = new Decimal(987.654321);
2368let data1: Decimal = data.toSignificantDigits();
2369console.info("test Decimal toSignificantDigits:" + data1.toString()); // 'test Decimal toSignificantDigits:987.654321'
2370```
2371
2372### toSignificantDigits
2373
2374toSignificantDigits(significantDigits: number): Decimal
2375
2376Converts this decimal into another one with the number of significant digits specified.
2377
2378You can use [DecimalConfig.rounding](#decimalconfig) to set the rounding mode.
2379
2380**Atomic service API**: This API can be used in atomic services since API version 12.
2381
2382**System capability**: SystemCapability.Utils.Lang
2383
2384**Parameters**
2385
2386| Name           | Type  | Mandatory| Description                  |
2387| ----------------- | ------ | ---- | ---------------------- |
2388| significantDigits | number | Yes  | Number of significant digits to reserve.|
2389
2390**Return value**
2391
2392| Type               | Description                                     |
2393| ------------------- | ----------------------------------------- |
2394| [Decimal](#decimal) | **Decimal** object with the specified number of significant digits.|
2395
2396**Error codes**
2397
2398For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
2399
2400| ID| Error Message                                         |
2401| -------- | ------------------------------------------------- |
2402| 10200001 | The value of 'significantDigits' is out of range. |
2403
2404**Example**
2405
2406```ts
2407let data: Decimal = new Decimal(987.654321);
2408let data1: Decimal = data.toSignificantDigits(6);
2409console.info("test Decimal toSignificantDigits:" + data1.toString()); // 'test Decimal toSignificantDigits:987.654'
2410```
2411
2412### toSignificantDigits
2413
2414toSignificantDigits(significantDigits: number, rounding: Rounding): Decimal
2415
2416Converts this decimal into another one with the number of significant digits and rounding mode specified.
2417
2418**Atomic service API**: This API can be used in atomic services since API version 12.
2419
2420**System capability**: SystemCapability.Utils.Lang
2421
2422**Parameters**
2423
2424| Name           | Type                 | Mandatory| Description                                                     |
2425| ----------------- | --------------------- | ---- | --------------------------------------------------------- |
2426| significantDigits | number                | Yes  | Number of significant digits to reserve. The value is an integer in the range of [1, 1e9].         |
2427| rounding          | [Rounding](#rounding) | Yes  | Rounding mode. For details, see [Rounding](#rounding).|
2428
2429**Return value**
2430
2431| Type               | Description                                     |
2432| ------------------- | ----------------------------------------- |
2433| [Decimal](#decimal) | **Decimal** object with the specified number of significant digits.|
2434
2435**Error codes**
2436
2437For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
2438
2439| ID| Error Message                                                    |
2440| -------- | ------------------------------------------------------------ |
2441| 10200001 | The value of 'significantDigits \|  rounding' is out of range. |
2442
2443**Example**
2444
2445```ts
2446let data: Decimal = new Decimal(987.654321);
2447let data1: Decimal = data.toSignificantDigits(6, Decimal.ROUND_UP);
2448console.info("test Decimal toSignificantDigits:" + data1.toString()); // 'test Decimal toSignificantDigits:987.655'
2449```
2450
2451### toNumber
2452
2453toNumber(): number
2454
2455Converts this decimal into a number.
2456
2457**Atomic service API**: This API can be used in atomic services since API version 12.
2458
2459**System capability**: SystemCapability.Utils.Lang
2460
2461**Return value**
2462
2463| Type  | Description                           |
2464| ------ | ------------------------------- |
2465| number | Number representing the decimal.|
2466
2467**Example**
2468
2469```ts
2470let data: Decimal = new Decimal(456.789);
2471let data1: number = data.toNumber();
2472console.info("test Decimal toNumber:" + data1.toString()); // 'test Decimal toNumber:456.789'
2473```
2474
2475### toString
2476
2477toString(): string
2478
2479Converts this decimal into a string. If the positive exponent of the decimal is greater than or equal to [toExpPos](#decimalconfig), or if the negative exponent is less than or equal to [toExpNeg](#decimalconfig), exponential notation is returned.
2480
2481**Atomic service API**: This API can be used in atomic services since API version 12.
2482
2483**System capability**: SystemCapability.Utils.Lang
2484
2485**Return value**
2486
2487| Type  | Description                         |
2488| ------ | ----------------------------- |
2489| string | String representing the decimal.|
2490
2491**Example**
2492
2493```ts
2494let data: Decimal = new Decimal(750000);
2495let data1: string = data.toString();
2496console.info("test Decimal toString:" + data1); // 'test Decimal toString:750000'
2497
2498Decimal.set({ toExpPos: 5 })
2499data1 = data.toString() // data1:'7.5e+5'
2500
2501let data2: Decimal = new Decimal(0.000000123)
2502console.info("test Decimal toString:" + data2.toString()); // 'test Decimal toString:1.23e-7'
2503
2504Decimal.set({ toExpNeg: -7 })
2505data1 = data2.toString() // data1:'1.23e-7'
2506```
2507
2508### valueOf
2509
2510valueOf(): string
2511
2512Returns a string representing the value of this decimal. Negative zeros contain minus signs.
2513
2514**Atomic service API**: This API can be used in atomic services since API version 12.
2515
2516**System capability**: SystemCapability.Utils.Lang
2517
2518**Return value**
2519
2520| Type  | Description                         |
2521| ------ | ----------------------------- |
2522| string | String representing the decimal.|
2523
2524**Example**
2525
2526```ts
2527let data: Decimal = new Decimal(-0);
2528let data1: string = data.valueOf();
2529console.info("test Decimal valueOf:" + data1); // 'test Decimal valueOf:-0'
2530```
2531
2532### decimalPlaces
2533
2534decimalPlaces(): number
2535
2536Returns the number of decimal places of this decimal.
2537
2538**Atomic service API**: This API can be used in atomic services since API version 12.
2539
2540**System capability**: SystemCapability.Utils.Lang
2541
2542**Return value**
2543
2544| Type  | Description                       |
2545| ------ | --------------------------- |
2546| number | Number of decimal places.|
2547
2548**Example**
2549
2550```ts
2551let data: Decimal = new Decimal(1.234);
2552let data1: number = data.decimalPlaces();
2553console.info("test Decimal decimalPlaces:" + data1); // 'test Decimal decimalPlaces:3'
2554```
2555
2556### precision
2557
2558precision(): number
2559
2560Returns the number of significant digits of this decimal.
2561
2562**Atomic service API**: This API can be used in atomic services since API version 12.
2563
2564**System capability**: SystemCapability.Utils.Lang
2565
2566**Return value**
2567
2568| Type  | Description                       |
2569| ------ | --------------------------- |
2570| number | Number of significant digits.|
2571
2572**Example**
2573
2574```ts
2575let data: Decimal = new Decimal(1.234);
2576let data1: number = data.precision();
2577console.info("test Decimal precision:" + data1); // 'test Decimal precision:4'
2578```
2579
2580### precision
2581
2582precision(includeZeros: boolean | number): number
2583
2584Returns the number of significant digits of this decimal, with **includeZeros** specified to determine whether to count the number of trailing zeros in the integer part.
2585
2586**Atomic service API**: This API can be used in atomic services since API version 12.
2587
2588**System capability**: SystemCapability.Utils.Lang
2589
2590**Parameters**
2591
2592| Name      | Type   | Mandatory| Description                                                        |
2593| ------------ | ------- | ---- | ------------------------------------------------------------ |
2594| includeZeros | boolean | Yes  | Whether to count the number of trailing zeros in the integer part. The value **true** means to count the number of trailing zeros in the integer part, and **false** means the opposite.|
2595
2596**Return value**
2597
2598| Type  | Description                       |
2599| ------ | --------------------------- |
2600| number | Number of significant digits.|
2601
2602**Error codes**
2603
2604For details about the error codes, see [Utils Error Codes](errorcode-utils.md).
2605
2606| ID| Error Message                                  |
2607| -------- | ------------------------------------------ |
2608| 10200001 | The value of includeZeros is out of range. |
2609
2610**Example**
2611
2612```ts
2613let data: Decimal = new Decimal(987000);
2614let data1: number = data.precision();
2615console.info("test Decimal precision:" + data1); // 'test Decimal precision:3'
2616data1 = data.precision(true) // data1:'6'
2617```
2618
2619### abs
2620
2621static abs(n: Value): Decimal
2622
2623Returns a **Decimal** object representing the absolute value of the specified number *n*.
2624
2625**Atomic service API**: This API can be used in atomic services since API version 12.
2626
2627**System capability**: SystemCapability.Utils.Lang
2628
2629**Parameters**
2630
2631| Name| Type           | Mandatory| Description            |
2632| ------ | --------------- | ---- | ---------------- |
2633| n      | [Value](#value) | Yes  | Target number to operate.|
2634
2635**Return value**
2636
2637| Type               | Description                                  |
2638| ------------------- | -------------------------------------- |
2639| [Decimal](#decimal) | **Decimal** object representing the absolute value.|
2640
2641**Error codes**
2642
2643For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2644
2645| ID| Error Message                                                    |
2646| -------- | ------------------------------------------------------------ |
2647| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
2648
2649**Example**
2650
2651```ts
2652let data: Decimal = Decimal.abs(-0.5);
2653console.info("test Decimal abs:" + data.toString()); // 'test Decimal abs:0.5'
2654```
2655
2656### floor
2657
2658static floor(n: Value): Decimal
2659
2660Returns a **Decimal** object representing the nearest integer to which the specified number *n* is rounded down.
2661
2662**Atomic service API**: This API can be used in atomic services since API version 12.
2663
2664**System capability**: SystemCapability.Utils.Lang
2665
2666**Parameters**
2667
2668| Name| Type           | Mandatory| Description          |
2669| ------ | --------------- | ---- | -------------- |
2670| n      | [Value](#value) | Yes  | Target number to operate.|
2671
2672**Return value**
2673
2674| Type               | Description                           |
2675| ------------------- | ------------------------------- |
2676| [Decimal](#decimal) | **Decimal** object representing the nearest integer rounded.|
2677
2678**Error codes**
2679
2680For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2681
2682| ID| Error Message                                                    |
2683| -------- | ------------------------------------------------------------ |
2684| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
2685
2686**Example**
2687
2688```ts
2689let data: Decimal = Decimal.floor(1.8);
2690console.info("test Decimal floor:" + data.toString()); // 'test Decimal floor:1'
2691```
2692
2693### ceil
2694
2695static ceil(n: Value): Decimal
2696
2697Returns a **Decimal** object representing the nearest integer to which the specified number *n* is rounded up.
2698
2699**Atomic service API**: This API can be used in atomic services since API version 12.
2700
2701**System capability**: SystemCapability.Utils.Lang
2702
2703**Parameters**
2704
2705| Name| Type           | Mandatory| Description          |
2706| ------ | --------------- | ---- | -------------- |
2707| n      | [Value](#value) | Yes  | Target number to operate.|
2708
2709**Return value**
2710
2711| Type               | Description                           |
2712| ------------------- | ------------------------------- |
2713| [Decimal](#decimal) | **Decimal** object representing the nearest integer rounded.|
2714
2715**Error codes**
2716
2717For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2718
2719| ID| Error Message                                                    |
2720| -------- | ------------------------------------------------------------ |
2721| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
2722
2723**Example**
2724
2725```ts
2726let data: Decimal = Decimal.ceil(1.8);
2727console.info("test Decimal ceil:" + data.toString()); // 'test Decimal ceil:2'
2728```
2729
2730### trunc
2731
2732static trunc(n: Value): Decimal
2733
2734Returns a **Decimal** object representing the integer part truncated from the specified number *n*.
2735
2736**Atomic service API**: This API can be used in atomic services since API version 12.
2737
2738**System capability**: SystemCapability.Utils.Lang
2739
2740**Parameters**
2741
2742| Name| Type           | Mandatory| Description          |
2743| ------ | --------------- | ---- | -------------- |
2744| n      | [Value](#value) | Yes  | Target number to operate.|
2745
2746**Return value**
2747
2748| Type               | Description                           |
2749| ------------------- | ------------------------------- |
2750| [Decimal](#decimal) | **Decimal** object representing the integer part.|
2751
2752**Error codes**
2753
2754For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2755
2756| ID| Error Message                                                    |
2757| -------- | ------------------------------------------------------------ |
2758| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
2759
2760**Example**
2761
2762```ts
2763let data: Decimal = Decimal.trunc(2.5);
2764console.info("test Decimal trunc:" + data.toString()); // 'test Decimal trunc:2'
2765```
2766
2767### clamp
2768
2769static clamp(n: Value, min: Value, max: Value): Decimal
2770
2771Returns a **Decimal** object representing the value clamped to the inclusive range of **min** and **max** of the specified number *n*.
2772
2773**Atomic service API**: This API can be used in atomic services since API version 12.
2774
2775**System capability**: SystemCapability.Utils.Lang
2776
2777**Parameters**
2778
2779| Name| Type           | Mandatory| Description                    |
2780| ------ | --------------- | ---- | ------------------------ |
2781| n      | [Value](#value) | Yes  | Value to be clamped.        |
2782| min    | [Value](#value) | Yes  | Lower bound of the range. This value is inclusive.|
2783| max    | [Value](#value) | Yes  | Upper bound of the range. This value is inclusive.|
2784
2785**Return value**
2786
2787| Type               | Description                           |
2788| ------------------- | ------------------------------- |
2789| [Decimal](#decimal) | **Decimal** object representing a value within the range.|
2790
2791**Error codes**
2792
2793For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Utils Error Codes](errorcode-utils.md).
2794
2795| ID| Error Message                                                    |
2796| -------- | ------------------------------------------------------------ |
2797| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
2798| 10200001 | The value of 'min' is out of range.                          |
2799
2800**Example**
2801
2802```ts
2803let data: Decimal = Decimal.clamp(10.1, 0, 10);
2804console.info("test Decimal clamp:" + data.toString()); // 'test Decimal clamp:10'
2805```
2806
2807### add
2808
2809static add(x: Value, y: Value): Decimal
2810
2811Returns a **Decimal** object representing the sum of two numbers *x* and *y*.
2812
2813You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
2814
2815**Atomic service API**: This API can be used in atomic services since API version 12.
2816
2817**System capability**: SystemCapability.Utils.Lang
2818
2819**Parameters**
2820
2821| Name| Type           | Mandatory| Description              |
2822| ------ | --------------- | ---- | ------------------ |
2823| x      | [Value](#value) | Yes  | Augend.  |
2824| y      | [Value](#value) | Yes  | Addend.|
2825
2826**Return value**
2827
2828| Type               | Description                             |
2829| ------------------- | --------------------------------- |
2830| [Decimal](#decimal) | **Decimal** object representing the sum.|
2831
2832**Error codes**
2833
2834For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2835
2836| ID| Error Message                                                    |
2837| -------- | ------------------------------------------------------------ |
2838| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
2839
2840**Example**
2841
2842```ts
2843let data: Decimal = Decimal.add(0.5, 0.5);
2844console.info("test Decimal add:" + data.toString()); // 'test Decimal add:1'
2845```
2846
2847### sum
2848
2849static sum(...n: Value[]): Decimal
2850
2851Returns a **Decimal** object representing the sum of elements in an array.
2852
2853You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
2854
2855**Atomic service API**: This API can be used in atomic services since API version 12.
2856
2857**System capability**: SystemCapability.Utils.Lang
2858
2859**Parameters**
2860
2861| Name| Type             | Mandatory| Description        |
2862| ------ | ----------------- | ---- | ------------ |
2863| n      | [Value](#value)[] | Yes  | Target array to operate.|
2864
2865**Return value**
2866
2867| Type               | Description                             |
2868| ------------------- | --------------------------------- |
2869| [Decimal](#decimal) | **Decimal** object representing the sum.|
2870
2871**Error codes**
2872
2873For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2874
2875| ID| Error Message                                                    |
2876| -------- | ------------------------------------------------------------ |
2877| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
2878
2879**Example**
2880
2881```ts
2882let data: Decimal = Decimal.sum(0.5, 0.5);
2883console.info("test Decimal sum:" + data.toString()); // 'test Decimal sum:1'
2884```
2885
2886### sub
2887
2888static sub(x: Value, y: Value): Decimal
2889
2890Returns a **Decimal** object representing the difference between two numbers *x* and *y*.
2891
2892You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
2893
2894**Atomic service API**: This API can be used in atomic services since API version 12.
2895
2896**System capability**: SystemCapability.Utils.Lang
2897
2898**Parameters**
2899
2900| Name| Type           | Mandatory| Description          |
2901| ------ | --------------- | ---- | -------------- |
2902| x      | [Value](#value) | Yes  | Minuend.|
2903| y      | [Value](#value) | Yes  | Subtrahend.  |
2904
2905**Return value**
2906
2907| Type               | Description                             |
2908| ------------------- | --------------------------------- |
2909| [Decimal](#decimal) | **Decimal** object representing the difference.|
2910
2911**Error codes**
2912
2913For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2914
2915| ID| Error Message                                                    |
2916| -------- | ------------------------------------------------------------ |
2917| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
2918
2919**Example**
2920
2921```ts
2922let data: Decimal = Decimal.sub(1, 0.5);
2923console.info("test Decimal sub:" + data.toString()); // 'test Decimal sub:0.5'
2924```
2925
2926### mul
2927
2928static mul(x: Value, y: Value): Decimal
2929
2930Returns a **Decimal** object representing the product of two numbers *x* and *y*.
2931
2932You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
2933
2934**Atomic service API**: This API can be used in atomic services since API version 12.
2935
2936**System capability**: SystemCapability.Utils.Lang
2937
2938**Parameters**
2939
2940| Name| Type           | Mandatory| Description          |
2941| ------ | --------------- | ---- | -------------- |
2942| x      | [Value](#value) | Yes  | Multiplier.|
2943| y      | [Value](#value) | Yes  | Multiplicand.  |
2944
2945**Return value**
2946
2947| Type               | Description                             |
2948| ------------------- | --------------------------------- |
2949| [Decimal](#decimal) | **Decimal** object representing the product.|
2950
2951**Error codes**
2952
2953For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2954
2955| ID| Error Message                                                    |
2956| -------- | ------------------------------------------------------------ |
2957| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
2958
2959**Example**
2960
2961```ts
2962let data: Decimal = Decimal.mul(1, 0.5);
2963console.info("test Decimal mul:" + data.toString()); // 'test Decimal mul:0.5'
2964```
2965
2966### div
2967
2968static div(x: Value, y: Value): Decimal
2969
2970Returns a **Decimal** object representing the quotient of two numbers *x* and *y*.
2971
2972You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
2973
2974**Atomic service API**: This API can be used in atomic services since API version 12.
2975
2976**System capability**: SystemCapability.Utils.Lang
2977
2978**Parameters**
2979
2980| Name| Type           | Mandatory| Description          |
2981| ------ | --------------- | ---- | -------------- |
2982| x      | [Value](#value) | Yes  | Dividend.|
2983| y      | [Value](#value) | Yes  | Divisor.  |
2984
2985**Return value**
2986
2987| Type               | Description                             |
2988| ------------------- | --------------------------------- |
2989| [Decimal](#decimal) | **Decimal** object representing the quotient.|
2990
2991**Error codes**
2992
2993For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
2994
2995| ID| Error Message                                                    |
2996| -------- | ------------------------------------------------------------ |
2997| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
2998
2999
3000**Example**
3001
3002```ts
3003let data: Decimal = Decimal.div(1, 0.5);
3004console.info("test Decimal div:" + data.toString()); // 'test Decimal div:2'
3005```
3006
3007### mod
3008
3009static mod(x: Value, y: Value): Decimal
3010
3011Returns a **Decimal** object representing the remainder of two numbers *x* and *y*.
3012
3013You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
3014
3015**Atomic service API**: This API can be used in atomic services since API version 12.
3016
3017**System capability**: SystemCapability.Utils.Lang
3018
3019**Parameters**
3020
3021| Name| Type           | Mandatory| Description              |
3022| ------ | --------------- | ---- | ------------------ |
3023| x      | [Value](#value) | Yes  | Dividend.|
3024| y      | [Value](#value) | Yes  | Divisor.  |
3025
3026**Return value**
3027
3028| Type               | Description                             |
3029| ------------------- | --------------------------------- |
3030| [Decimal](#decimal) | **Decimal** object representing the remainder.|
3031
3032**Error codes**
3033
3034For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3035
3036| ID| Error Message                                                    |
3037| -------- | ------------------------------------------------------------ |
3038| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
3039
3040**Example**
3041
3042```ts
3043let data: Decimal = Decimal.mod(2, 1);
3044console.info("test Decimal mod:" + data.toString()); // 'test Decimal mod:0'
3045```
3046
3047### sqrt
3048
3049static sqrt(n: Value): Decimal
3050
3051Returns a **Decimal** object representing the square root of the specified number *n*.
3052
3053You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
3054
3055**Atomic service API**: This API can be used in atomic services since API version 12.
3056
3057**System capability**: SystemCapability.Utils.Lang
3058
3059**Parameters**
3060
3061| Name| Type           | Mandatory| Description          |
3062| ------ | --------------- | ---- | -------------- |
3063| n      | [Value](#value) | Yes  | Target number to operate.|
3064
3065**Return value**
3066
3067| Type               | Description                               |
3068| ------------------- | ----------------------------------- |
3069| [Decimal](#decimal) | **Decimal** object representing the square root.|
3070
3071**Error codes**
3072
3073For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3074
3075| ID| Error Message                                                    |
3076| -------- | ------------------------------------------------------------ |
3077| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
3078
3079**Example**
3080
3081```ts
3082let data: Decimal = Decimal.sqrt(3);
3083console.info("test Decimal sqrt:" + data.toString()); // 'test Decimal sqrt:1.7320508075688772935'
3084```
3085
3086### cbrt
3087
3088static cbrt(n: Value): Decimal
3089
3090Returns a **Decimal** object representing the cube root of the specified number *n*.
3091
3092You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
3093
3094**Atomic service API**: This API can be used in atomic services since API version 12.
3095
3096**System capability**: SystemCapability.Utils.Lang
3097
3098**Parameters**
3099
3100| Name| Type           | Mandatory| Description          |
3101| ------ | --------------- | ---- | -------------- |
3102| n      | [Value](#value) | Yes  | Target number to operate.|
3103
3104**Return value**
3105
3106| Type               | Description                               |
3107| ------------------- | ----------------------------------- |
3108| [Decimal](#decimal) | **Decimal** object representing the cube root.|
3109
3110**Error codes**
3111
3112For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3113
3114| ID| Error Message                                                    |
3115| -------- | ------------------------------------------------------------ |
3116| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
3117
3118**Example**
3119
3120```ts
3121let data: Decimal = Decimal.cbrt(3);
3122console.info("test Decimal cbrt:" + data.toString()); // 'test Decimal cbrt:1.4422495703074083823'
3123```
3124
3125### pow
3126
3127static pow(base: Value, exponent: Value): Decimal
3128
3129Returns a **Decimal** object representing the value resulting from raising a number to the power of another number. You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
3130
3131**Atomic service API**: This API can be used in atomic services since API version 12.
3132
3133**System capability**: SystemCapability.Utils.Lang
3134
3135**Parameters**
3136
3137| Name  | Type           | Mandatory| Description              |
3138| -------- | --------------- | ---- | ------------------ |
3139| base     | [Value](#value) | Yes  | Base of the exponentiation operation.|
3140| exponent | [Value](#value) | Yes  | Power of the exponentiation operation.  |
3141
3142**Return value**
3143
3144| Type               | Description                           |
3145| ------------------- | ------------------------------- |
3146| [Decimal](#decimal) | **Decimal** object representing the result of the exponentiation operation.|
3147
3148**Error codes**
3149
3150For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Utils Error Codes](errorcode-utils.md).
3151
3152| ID| Error Message                                                    |
3153| -------- | ------------------------------------------------------------ |
3154| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
3155| 10200060 | Precision limit exceeded.                                    |
3156
3157**Example**
3158
3159```ts
3160let data: Decimal = Decimal.pow(3, -2);
3161console.info("test Decimal pow:" + data.toString()); // 'test Decimal pow:0.11111111111111111111'
3162```
3163
3164### exp
3165
3166static exp(n: Value): Decimal
3167
3168Returns a **Decimal** object representing the value resulting from raising e to the power of the specified number *n*.
3169
3170You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
3171
3172**Atomic service API**: This API can be used in atomic services since API version 12.
3173
3174**System capability**: SystemCapability.Utils.Lang
3175
3176**Parameters**
3177
3178| Name| Type           | Mandatory| Description                |
3179| ------ | --------------- | ---- | -------------------- |
3180| n      | [Value](#value) | Yes  | Power of the natural exponentiation operation.|
3181
3182**Return value**
3183
3184| Type               | Description                                 |
3185| ------------------- | ------------------------------------- |
3186| [Decimal](#decimal) | **Decimal** object representing the result of the natural exponentiation operation.|
3187
3188**Error codes**
3189
3190For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Utils Error Codes](errorcode-utils.md).
3191
3192| ID| Error Message                                                    |
3193| -------- | ------------------------------------------------------------ |
3194| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
3195| 10200060 | Precision limit exceeded.                                    |
3196
3197**Example**
3198
3199```ts
3200let data: Decimal = Decimal.exp(2);
3201console.info("test Decimal exp:" + data.toString()); // 'test Decimal exp:7.3890560989306502272'
3202```
3203
3204### log
3205
3206static log(n: Value, base: Value): Decimal
3207
3208Returns a **Decimal** object representing the logarithm of the specified number *n* to the specified base.
3209
3210You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
3211
3212**Atomic service API**: This API can be used in atomic services since API version 12.
3213
3214**System capability**: SystemCapability.Utils.Lang
3215
3216**Parameters**
3217
3218| Name| Type           | Mandatory| Description            |
3219| ------ | --------------- | ---- | ---------------- |
3220| n      | [Value](#value) | Yes  | Real number of the logarithmic operation.|
3221| base   | [Value](#value) | Yes  | Base of the logarithmic operation.  |
3222
3223**Return value**
3224
3225| Type               | Description                             |
3226| ------------------- | --------------------------------- |
3227| [Decimal](#decimal) | **Decimal** object representing the logarithm.|
3228
3229**Error codes**
3230
3231For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Utils Error Codes](errorcode-utils.md).
3232
3233| ID| Error Message                                                    |
3234| -------- | ------------------------------------------------------------ |
3235| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
3236| 10200060 | Precision limit exceeded.                                    |
3237
3238**Example**
3239
3240```ts
3241let data: Decimal = Decimal.log(2, 256);
3242console.info("test Decimal log:" + data.toString()); // 'test Decimal log:0.125'
3243```
3244
3245### ln
3246
3247static ln(n: Value): Decimal
3248
3249Returns a **Decimal** object representing the natural logarithm of the specified number *n*.
3250
3251You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
3252
3253**Atomic service API**: This API can be used in atomic services since API version 12.
3254
3255**System capability**: SystemCapability.Utils.Lang
3256
3257**Parameters**
3258
3259| Name| Type           | Mandatory| Description            |
3260| ------ | --------------- | ---- | ---------------- |
3261| n      | [Value](#value) | Yes  | Real number of the logarithmic operation.|
3262
3263**Return value**
3264
3265| Type               | Description                                 |
3266| ------------------- | ------------------------------------- |
3267| [Decimal](#decimal) | **Decimal** object representing the natural logarithm.|
3268
3269**Error codes**
3270
3271For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Utils Error Codes](errorcode-utils.md).
3272
3273| ID| Error Message                                                    |
3274| -------- | ------------------------------------------------------------ |
3275| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
3276| 10200060 | Precision limit exceeded.                                    |
3277
3278**Example**
3279
3280```ts
3281let data: Decimal = Decimal.ln(1.23e+30);
3282console.info("test Decimal ln:" + data.toString()); // 'test Decimal ln:69.284566959205696648'
3283```
3284
3285### log2
3286
3287static log2(n: Value): Decimal
3288
3289Returns a **Decimal** object representing the base 2 logarithm of the specified number *n*.
3290
3291You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
3292
3293**Atomic service API**: This API can be used in atomic services since API version 12.
3294
3295**System capability**: SystemCapability.Utils.Lang
3296
3297**Parameters**
3298
3299| Name| Type           | Mandatory| Description            |
3300| ------ | --------------- | ---- | ---------------- |
3301| n      | [Value](#value) | Yes  | Real number of the logarithmic operation.|
3302
3303**Return value**
3304
3305| Type               | Description                                      |
3306| ------------------- | ------------------------------------------ |
3307| [Decimal](#decimal) | **Decimal** object representing the base 2 logarithm of the specified number.|
3308
3309**Error codes**
3310
3311For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Utils Error Codes](errorcode-utils.md).
3312
3313| ID| Error Message                                                    |
3314| -------- | ------------------------------------------------------------ |
3315| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
3316| 10200060 | Precision limit exceeded.                                    |
3317
3318**Example**
3319
3320```ts
3321let data: Decimal = Decimal.log2(4);
3322console.info("test Decimal log2:" + data.toString()); // 'test Decimal log2:2'
3323```
3324
3325### log10
3326
3327static log10(n: Value): Decimal
3328
3329Returns a **Decimal** object representing the base 10 logarithm of the specified number *n*.
3330
3331You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
3332
3333**Atomic service API**: This API can be used in atomic services since API version 12.
3334
3335**System capability**: SystemCapability.Utils.Lang
3336
3337**Parameters**
3338
3339| Name| Type           | Mandatory| Description            |
3340| ------ | --------------- | ---- | ---------------- |
3341| n      | [Value](#value) | Yes  | Real number of the logarithmic operation.|
3342
3343**Return value**
3344
3345| Type               | Description                                       |
3346| ------------------- | ------------------------------------------- |
3347| [Decimal](#decimal) | **Decimal** object representing the base 10 logarithm of the specified number.|
3348
3349**Error codes**
3350
3351For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Utils Error Codes](errorcode-utils.md).
3352
3353| ID| Error Message                                                    |
3354| -------- | ------------------------------------------------------------ |
3355| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
3356| 10200060 | Precision limit exceeded.                                    |
3357
3358**Example**
3359
3360```ts
3361let data: Decimal = Decimal.log10(10000);
3362console.info("test Decimal log10:" + data.toString()); // 'test Decimal log10:4'
3363```
3364
3365### cos
3366
3367static cos(n: Value): Decimal
3368
3369Returns a **Decimal** object representing the cosine of the specified number *n*.
3370
3371You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
3372
3373**Atomic service API**: This API can be used in atomic services since API version 12.
3374
3375**System capability**: SystemCapability.Utils.Lang
3376
3377**Parameters**
3378
3379| Name| Type           | Mandatory| Description            |
3380| ------ | --------------- | ---- | ---------------- |
3381| n      | [Value](#value) | Yes  | Target number to operate.|
3382
3383**Return value**
3384
3385| Type               | Description                                  |
3386| ------------------- | -------------------------------------- |
3387| [Decimal](#decimal) | **Decimal** object representing the cosine.|
3388
3389**Error codes**
3390
3391For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3392
3393| ID| Error Message                                                    |
3394| -------- | ------------------------------------------------------------ |
3395| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
3396
3397**Example**
3398
3399```ts
3400let data: Decimal = Decimal.cos(-0.25);
3401console.info("test Decimal cos:" + data.toString()); // 'test Decimal cos:0.96891242171064478414'
3402```
3403
3404### sin
3405
3406static sin(n: Value): Decimal
3407
3408Returns a **Decimal** object representing the sine of the specified number *n*.
3409
3410You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
3411
3412**Atomic service API**: This API can be used in atomic services since API version 12.
3413
3414**System capability**: SystemCapability.Utils.Lang
3415
3416**Parameters**
3417
3418| Name| Type           | Mandatory| Description            |
3419| ------ | --------------- | ---- | ---------------- |
3420| n      | [Value](#value) | Yes  | Target number to operate.|
3421
3422**Return value**
3423
3424| Type               | Description                                  |
3425| ------------------- | -------------------------------------- |
3426| [Decimal](#decimal) | **Decimal** object representing the sine.|
3427
3428**Error codes**
3429
3430For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3431
3432| ID| Error Message                                                    |
3433| -------- | ------------------------------------------------------------ |
3434| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
3435
3436**Example**
3437
3438```ts
3439let data: Decimal = Decimal.sin(0.75);
3440console.info("test Decimal sin:" + data.toString()); // 'test Decimal sin:0.68163876002333416673'
3441```
3442
3443### tan
3444
3445static tan(n: Value): Decimal
3446
3447Returns a **Decimal** object representing the tangent of the specified number *n*.
3448
3449You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
3450
3451**Atomic service API**: This API can be used in atomic services since API version 12.
3452
3453**System capability**: SystemCapability.Utils.Lang
3454
3455**Parameters**
3456
3457| Name| Type           | Mandatory| Description            |
3458| ------ | --------------- | ---- | ---------------- |
3459| n      | [Value](#value) | Yes  | Target number to operate.|
3460
3461**Return value**
3462
3463| Type               | Description                                  |
3464| ------------------- | -------------------------------------- |
3465| [Decimal](#decimal) | **Decimal** object representing the tangent.|
3466
3467**Error codes**
3468
3469For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3470
3471| ID| Error Message                                                    |
3472| -------- | ------------------------------------------------------------ |
3473| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
3474
3475**Example**
3476
3477```ts
3478let data: Decimal = Decimal.tan(0.75);
3479console.info("test Decimal tan:" + data.toString()); // 'test Decimal tan:0.93159645994407246117'
3480```
3481
3482### cosh
3483
3484static cosh(n: Value): Decimal
3485
3486Returns a **Decimal** object representing the hyperbolic cosine of the specified number *n*.
3487
3488You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
3489
3490**Atomic service API**: This API can be used in atomic services since API version 12.
3491
3492**System capability**: SystemCapability.Utils.Lang
3493
3494**Parameters**
3495
3496| Name| Type           | Mandatory| Description                  |
3497| ------ | --------------- | ---- | ---------------------- |
3498| n      | [Value](#value) | Yes  | Target number to operate.|
3499
3500**Return value**
3501
3502| Type               | Description                                      |
3503| ------------------- | ------------------------------------------ |
3504| [Decimal](#decimal) | **Decimal** object representing the hyperbolic cosine.|
3505
3506**Error codes**
3507
3508For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3509
3510| ID| Error Message                                                    |
3511| -------- | ------------------------------------------------------------ |
3512| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
3513
3514**Example**
3515
3516```ts
3517let data: Decimal = Decimal.cosh(0.5);
3518console.info("test Decimal cosh:" + data.toString()); // 'test Decimal cosh:1.1276259652063807852'
3519```
3520
3521### sinh
3522
3523static sinh(n: Value): Decimal
3524
3525Returns a **Decimal** object representing the hyperbolic sine of the specified number *n*.
3526
3527You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
3528
3529**Atomic service API**: This API can be used in atomic services since API version 12.
3530
3531**System capability**: SystemCapability.Utils.Lang
3532
3533**Parameters**
3534
3535| Name| Type           | Mandatory| Description                  |
3536| ------ | --------------- | ---- | ---------------------- |
3537| n      | [Value](#value) | Yes  | Target number to operate.|
3538
3539**Return value**
3540
3541| Type               | Description                                      |
3542| ------------------- | ------------------------------------------ |
3543| [Decimal](#decimal) | **Decimal** object representing the hyperbolic sine.|
3544
3545**Error codes**
3546
3547For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3548
3549| ID| Error Message                                                    |
3550| -------- | ------------------------------------------------------------ |
3551| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
3552
3553**Example**
3554
3555```ts
3556let data: Decimal = Decimal.sinh(0.5);
3557console.info("test Decimal sinh:" + data.toString()); // 'test Decimal sinh:0.52109530549374736162'
3558```
3559
3560### tanh
3561
3562static tanh(n: Value): Decimal
3563
3564Returns a **Decimal** object representing the hyperbolic tangent of the specified number *n*.
3565
3566You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
3567
3568**Atomic service API**: This API can be used in atomic services since API version 12.
3569
3570**System capability**: SystemCapability.Utils.Lang
3571
3572**Parameters**
3573
3574| Name| Type           | Mandatory| Description                  |
3575| ------ | --------------- | ---- | ---------------------- |
3576| n      | [Value](#value) | Yes  | Target number to operate.|
3577
3578**Return value**
3579
3580| Type               | Description                                      |
3581| ------------------- | ------------------------------------------ |
3582| [Decimal](#decimal) | **Decimal** object representing the hyperbolic tangent.|
3583
3584**Error codes**
3585
3586For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3587
3588| ID| Error Message                                                    |
3589| -------- | ------------------------------------------------------------ |
3590| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
3591
3592**Example**
3593
3594```ts
3595let data: Decimal = Decimal.tanh(0.5);
3596console.info("test Decimal tanh:" + data.toString()); // 'test Decimal tanh:0.4621171572600097585'
3597```
3598
3599### acos
3600
3601static acos(n: Value): Decimal
3602
3603Returns a **Decimal** object representing the arc cosine of the specified number *n*.
3604
3605You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
3606
3607**Atomic service API**: This API can be used in atomic services since API version 12.
3608
3609**System capability**: SystemCapability.Utils.Lang
3610
3611**Parameters**
3612
3613| Name| Type           | Mandatory| Description                |
3614| ------ | --------------- | ---- | -------------------- |
3615| n      | [Value](#value) | Yes  | Target number to operate.|
3616
3617**Return value**
3618
3619| Type               | Description                                  |
3620| ------------------- | -------------------------------------- |
3621| [Decimal](#decimal) | **Decimal** object representing the arc cosine.|
3622
3623**Error codes**
3624
3625For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Utils Error Codes](errorcode-utils.md).
3626
3627| ID| Error Message                                                    |
3628| -------- | ------------------------------------------------------------ |
3629| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
3630| 10200060 | Precision limit exceeded.                                    |
3631
3632**Example**
3633
3634```ts
3635let data: Decimal = Decimal.acos(0.5);
3636console.info("test Decimal acos:" + data.toString()); // 'test Decimal acos:1.0471975511965977462'
3637```
3638
3639### asin
3640
3641static asin(n: Value): Decimal
3642
3643Returns a **Decimal** object representing the arc sine of the specified number *n*.
3644
3645You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
3646
3647**Atomic service API**: This API can be used in atomic services since API version 12.
3648
3649**System capability**: SystemCapability.Utils.Lang
3650
3651**Parameters**
3652
3653| Name| Type           | Mandatory| Description                |
3654| ------ | --------------- | ---- | -------------------- |
3655| n      | [Value](#value) | Yes  | Target number to operate.|
3656
3657**Return value**
3658
3659| Type               | Description                                  |
3660| ------------------- | -------------------------------------- |
3661| [Decimal](#decimal) | **Decimal** object representing the arc sine.|
3662
3663**Error codes**
3664
3665For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Utils Error Codes](errorcode-utils.md).
3666
3667| ID| Error Message                                                    |
3668| -------- | ------------------------------------------------------------ |
3669| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
3670| 10200060 | Precision limit exceeded.                                    |
3671
3672**Example**
3673
3674```ts
3675let data: Decimal = Decimal.asin(0.75);
3676console.info("test Decimal asin:" + data.toString()); // 'test Decimal asin:0.84806207898148100805'
3677```
3678
3679### atan
3680
3681static atan(n: Value): Decimal
3682
3683Returns a **Decimal** object representing the arc tangent of the specified number *n*.
3684
3685You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
3686
3687**Atomic service API**: This API can be used in atomic services since API version 12.
3688
3689**System capability**: SystemCapability.Utils.Lang
3690
3691**Parameters**
3692
3693| Name| Type           | Mandatory| Description                |
3694| ------ | --------------- | ---- | -------------------- |
3695| n      | [Value](#value) | Yes  | Target number to operate.|
3696
3697**Return value**
3698
3699| Type               | Description                                  |
3700| ------------------- | -------------------------------------- |
3701| [Decimal](#decimal) | **Decimal** object representing the arc tangent.|
3702
3703**Error codes**
3704
3705For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Utils Error Codes](errorcode-utils.md).
3706
3707| ID| Error Message                                                    |
3708| -------- | ------------------------------------------------------------ |
3709| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
3710| 10200060 | Precision limit exceeded.                                    |
3711
3712**Example**
3713
3714```ts
3715let data: Decimal = Decimal.atan(0.75);
3716console.info("test Decimal atan:" + data.toString()); // 'test Decimal atan:0.6435011087932843868'
3717```
3718
3719### acosh
3720
3721static acosh(n: Value): Decimal
3722
3723Returns a **Decimal** object representing the inverse hyperbolic cosine of the specified number *n*.
3724
3725You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
3726
3727**Atomic service API**: This API can be used in atomic services since API version 12.
3728
3729**System capability**: SystemCapability.Utils.Lang
3730
3731**Parameters**
3732
3733| Name| Type           | Mandatory| Description                      |
3734| ------ | --------------- | ---- | -------------------------- |
3735| n      | [Value](#value) | Yes  | Target number to operate.|
3736
3737**Return value**
3738
3739| Type               | Description                                          |
3740| ------------------- | ---------------------------------------------- |
3741| [Decimal](#decimal) | **Decimal** object representing the inverse hyperbolic cosine.|
3742
3743**Error codes**
3744
3745For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Utils Error Codes](errorcode-utils.md).
3746
3747| ID| Error Message                                                    |
3748| -------- | ------------------------------------------------------------ |
3749| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
3750| 10200060 | Precision limit exceeded.                                    |
3751
3752**Example**
3753
3754```ts
3755let data: Decimal = Decimal.acosh(50);
3756console.info("test Decimal acosh:" + data.toString()); // 'test Decimal acosh:4.6050701709847571595'
3757```
3758
3759### asinh
3760
3761static asinh(n: Value): Decimal
3762
3763Returns a **Decimal** object representing the inverse hyperbolic sine of the specified number *n*.
3764
3765You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
3766
3767**Atomic service API**: This API can be used in atomic services since API version 12.
3768
3769**System capability**: SystemCapability.Utils.Lang
3770
3771**Parameters**
3772
3773| Name| Type           | Mandatory| Description                      |
3774| ------ | --------------- | ---- | -------------------------- |
3775| n      | [Value](#value) | Yes  | Target number to operate.|
3776
3777**Return value**
3778
3779| Type               | Description                                          |
3780| ------------------- | ---------------------------------------------- |
3781| [Decimal](#decimal) | **Decimal** object representing the inverse hyperbolic sine.|
3782
3783**Error codes**
3784
3785For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Utils Error Codes](errorcode-utils.md).
3786
3787| ID| Error Message                                                    |
3788| -------- | ------------------------------------------------------------ |
3789| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
3790| 10200060 | Precision limit exceeded.                                    |
3791
3792**Example**
3793
3794```ts
3795let data: Decimal = Decimal.asinh(50);
3796console.info("test Decimal asinh:" + data.toString()); // 'test Decimal asinh:4.6052701709914238266'
3797```
3798
3799### atanh
3800
3801static atanh(n: Value): Decimal
3802
3803Returns a **Decimal** object representing the inverse hyperbolic tangent of the specified number *n*.
3804
3805You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
3806
3807**Atomic service API**: This API can be used in atomic services since API version 12.
3808
3809**System capability**: SystemCapability.Utils.Lang
3810
3811**Parameters**
3812
3813| Name| Type           | Mandatory| Description                      |
3814| ------ | --------------- | ---- | -------------------------- |
3815| n      | [Value](#value) | Yes  | Target number to operate.|
3816
3817**Return value**
3818
3819| Type               | Description                                          |
3820| ------------------- | ---------------------------------------------- |
3821| [Decimal](#decimal) | **Decimal** object representing the inverse hyperbolic tangent.|
3822
3823**Error codes**
3824
3825For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Utils Error Codes](errorcode-utils.md).
3826
3827| ID| Error Message                                                    |
3828| -------- | ------------------------------------------------------------ |
3829| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
3830| 10200060 | Precision limit exceeded.                                    |
3831
3832**Example**
3833
3834```ts
3835let data: Decimal = Decimal.atanh(0.75);
3836console.info("test Decimal atanh:" + data.toString()); // 'test Decimal atanh:0.97295507452765665255'
3837```
3838
3839### atan2
3840
3841static atan2(y: Value, x: Value): Decimal
3842
3843Returns a **Decimal** object representing the arc tangent of y/x in the range from -π to π.
3844
3845You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
3846
3847**Atomic service API**: This API can be used in atomic services since API version 12.
3848
3849**System capability**: SystemCapability.Utils.Lang
3850
3851**Parameters**
3852
3853| Name| Type           | Mandatory| Description          |
3854| ------ | --------------- | ---- | -------------- |
3855| y      | [Value](#value) | Yes  | Dividend.|
3856| x      | [Value](#value) | Yes  | Divisor.  |
3857
3858**Return value**
3859
3860| Type               | Description                                                      |
3861| ------------------- | ---------------------------------------------------------- |
3862| [Decimal](#decimal) | **Decimal** object representing the arc tangent of y/x in the range from -π to π.|
3863
3864**Error codes**
3865
3866For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Utils Error Codes](errorcode-utils.md).
3867
3868| ID| Error Message                                                    |
3869| -------- | ------------------------------------------------------------ |
3870| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
3871| 10200060 | Precision limit exceeded.                                    |
3872
3873**Example**
3874
3875```ts
3876let data: Decimal = Decimal.atan2(2, 3);
3877console.info("test Decimal atan2:" + data.toString()); // 'test Decimal atan2:0.58800260354756755125'
3878```
3879
3880### hypot
3881
3882static hypot(...n: Value[]): Decimal
3883
3884Returns a **Decimal** object representing the Euclidean norm of elements in an array.
3885
3886You can use [DecimalConfig.precision](#decimalconfig) to specify the precision and use [DecimalConfig.rounding](#decimalconfig) to specify the rounding mode.
3887
3888**Atomic service API**: This API can be used in atomic services since API version 12.
3889
3890**System capability**: SystemCapability.Utils.Lang
3891
3892**Parameters**
3893
3894| Name| Type             | Mandatory| Description                |
3895| ------ | ----------------- | ---- | -------------------- |
3896| n      | [Value](#value)[] | Yes  | Target array to operate.|
3897
3898**Return value**
3899
3900| Type               | Description                                             |
3901| ------------------- | ------------------------------------------------- |
3902| [Decimal](#decimal) | **Decimal** object representing the Euclidean norm of the elements.|
3903
3904**Error codes**
3905
3906For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3907
3908| ID| Error Message                                                    |
3909| -------- | ------------------------------------------------------------ |
3910| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
3911
3912**Example**
3913
3914```ts
3915let data: Decimal = Decimal.hypot(2, 3, 4);
3916console.info("test Decimal hypot:" + data.toString()); // 'test Decimal hypot:5.3851648071345040313'
3917```
3918
3919### max
3920
3921static max(...n: Value[]): Decimal
3922
3923Returns a **Decimal** object representing the maximum value among all elements in an array.
3924
3925**Atomic service API**: This API can be used in atomic services since API version 12.
3926
3927**System capability**: SystemCapability.Utils.Lang
3928
3929**Parameters**
3930
3931| Name| Type             | Mandatory| Description                |
3932| ------ | ----------------- | ---- | -------------------- |
3933| n      | [Value](#value)[] | Yes  | Target array to operate.|
3934
3935**Return value**
3936
3937| Type               | Description                                     |
3938| ------------------- | ----------------------------------------- |
3939| [Decimal](#decimal) | **Decimal** object representing the maximum value.|
3940
3941**Error codes**
3942
3943For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3944
3945| ID| Error Message                                                    |
3946| -------- | ------------------------------------------------------------ |
3947| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
3948
3949**Example**
3950
3951```ts
3952let data: Decimal = Decimal.max(2, 3, 4);
3953console.info("test Decimal max:" + data.toString()); // 'test Decimal max:4'
3954```
3955
3956### min
3957
3958static min(...n: Value[]): Decimal
3959
3960Returns a **Decimal** object representing the minimum value among all elements in an array.
3961
3962**Atomic service API**: This API can be used in atomic services since API version 12.
3963
3964**System capability**: SystemCapability.Utils.Lang
3965
3966**Parameters**
3967
3968| Name| Type           | Mandatory| Description                |
3969| ------ | --------------- | ---- | -------------------- |
3970| n      | [Value](#value)[] | Yes  | Target array to operate.|
3971
3972**Return value**
3973
3974| Type               | Description                                     |
3975| ------------------- | ----------------------------------------- |
3976| [Decimal](#decimal) | **Decimal** object representing the minimum value.|
3977
3978**Error codes**
3979
3980For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
3981
3982| ID| Error Message                                                    |
3983| -------- | ------------------------------------------------------------ |
3984| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
3985
3986**Example**
3987
3988```ts
3989let data: Decimal = Decimal.min(2, 3, 4);
3990console.info("test Decimal min:" + data.toString()); // 'test Decimal min:2'
3991```
3992
3993### random
3994
3995static random(): Decimal
3996
3997Returns a **Decimal** object representing a random number in the range [0, 1).
3998
3999**Atomic service API**: This API can be used in atomic services since API version 12.
4000
4001**System capability**: SystemCapability.Utils.Lang
4002
4003**Return value**
4004
4005| Type               | Description                                     |
4006| ------------------- | ----------------------------------------- |
4007| [Decimal](#decimal) | **Decimal** object representing a random number in the range [0, 1).|
4008
4009**Error codes**
4010
4011For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Utils Error Codes](errorcode-utils.md).
4012
4013| ID| Error Message           |
4014| -------- | ------------------- |
4015| 10200061 | Crypto unavailable. |
4016
4017**Example**
4018
4019```ts
4020let data: Decimal = Decimal.random();
4021```
4022
4023### random
4024
4025static random(significantDigits: number): Decimal
4026
4027Returns a **Decimal** object representing a random number in the range [0, 1), with the number of significant digits specified.
4028
4029**Atomic service API**: This API can be used in atomic services since API version 12.
4030
4031**System capability**: SystemCapability.Utils.Lang
4032
4033**Parameters**
4034
4035| Name           | Type  | Mandatory| Description                  |
4036| ----------------- | ------ | ---- | ---------------------- |
4037| significantDigits | number | Yes  | Number of significant digits reserved for the random number.|
4038
4039**Return value**
4040
4041| Type               | Description                                     |
4042| ------------------- | ----------------------------------------- |
4043| [Decimal](#decimal) | **Decimal** object representing a random number in the range [0, 1).|
4044
4045**Error codes**
4046
4047For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Utils Error Codes](errorcode-utils.md).
4048
4049| ID| Error Message                                                    |
4050| -------- | ------------------------------------------------------------ |
4051| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
4052| 10200061 | Crypto unavailable.                                          |
4053
4054**Example**
4055
4056```ts
4057let data: Decimal = Decimal.random(20);
4058```
4059
4060### sign
4061
4062static sign(n: Value): number
4063
4064Checks the specified number **n**. In the case of n>0, **1** is returned; in the case of n<0, **-1** is returned; in the case of n==0, **0** is returned; in the case of n==-0, **-0** is returned; in any other cases, **NaN** is returned.
4065
4066**Atomic service API**: This API can be used in atomic services since API version 12.
4067
4068**System capability**: SystemCapability.Utils.Lang
4069
4070**Parameters**
4071
4072| Name| Type           | Mandatory| Description          |
4073| ------ | --------------- | ---- | -------------- |
4074| n      | [Value](#value) | Yes  | Number to check.|
4075
4076**Return value**
4077
4078| Type  | Description                              |
4079| ------ | ---------------------------------- |
4080| number | Value based on the check result.|
4081
4082**Error codes**
4083
4084For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4085
4086| ID| Error Message                                                    |
4087| -------- | ------------------------------------------------------------ |
4088| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
4089
4090**Example**
4091
4092```ts
4093let data: number = Decimal.sign(2);
4094console.info("test Decimal sign:" + data); // 'test Decimal sign:1'
4095```
4096
4097### round
4098
4099static round(n: Value): Decimal
4100
4101Returns a **Decimal** object representing the specified number *n* rounded to an integer using the rounding mode specified by [DecimalConfig.rounding](#decimalconfig).
4102
4103**Atomic service API**: This API can be used in atomic services since API version 12.
4104
4105**System capability**: SystemCapability.Utils.Lang
4106
4107**Parameters**
4108
4109| Name| Type           | Mandatory| Description          |
4110| ------ | --------------- | ---- | -------------- |
4111| n      | [Value](#value) | Yes  | Target number to operate.|
4112
4113**Return value**
4114
4115| Type               | Description                                     |
4116| ------------------- | ----------------------------------------- |
4117| [Decimal](#decimal) | **Decimal** object representing the integer rounded.|
4118
4119**Error codes**
4120
4121For details about the error codes, see [Universal Error Codes](../errorcode-universal.md).
4122
4123| ID| Error Message                                                    |
4124| -------- | ------------------------------------------------------------ |
4125| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
4126
4127**Example**
4128
4129```ts
4130let x = 3.3333333333333;
4131let data = Decimal.round(x);
4132console.info("test Decimal round:" + data.toString()); // 'test Decimal round:3'
4133```
4134
4135### set
4136
4137static set(object: DecimalConfig):void
4138
4139Sets the properties for this **Decimal** object. The properties set by calling this API take effect globally.
4140
4141**Atomic service API**: This API can be used in atomic services since API version 12.
4142
4143**System capability**: SystemCapability.Utils.Lang
4144
4145**Parameters**
4146
4147| Name| Type                           | Mandatory| Description                |
4148| ------ | ------------------------------- | ---- | -------------------- |
4149| object | [DecimalConfig](#decimalconfig) | Yes  | Properties to set.|
4150
4151**Error codes**
4152
4153For details about the error codes, see [Universal Error Codes](../errorcode-universal.md) and [Utils Error Codes](errorcode-utils.md).
4154
4155| ID| Error Message                                                    |
4156| -------- | ------------------------------------------------------------ |
4157| 401      | Parameter error. Possible causes:<br>1. Incorrect parameter types;<br>2. Parameter verification failed. |
4158| 10200001 | The value of 'DecimalConfig.properties' is out of range.     |
4159| 10200061 | Crypto unavailable.                                          |
4160
4161**Example 1**
4162
4163```ts
4164let data : Decimal = new Decimal(1.2345678901234567);
4165Decimal.set({
4166    precision: 5,
4167    rounding: 4,
4168    toExpNeg: -7,
4169    toExpPos: 7,
4170    maxE: 9e15,
4171    minE: -9e15,
4172    modulo: 1,
4173    crypto: false
4174})
4175let data1 : Decimal = data.add(0.5);
4176console.info("test Decimal set:" + data1.toString()); // "test Decimal set:1.7346"
4177// Set all properties to their default values.
4178Decimal.set({ defaults: true })
4179let data2 : Decimal = data.add(0.5);
4180console.info("test Decimal set:" + data2.toString()); // "test Decimal set:1.7345678901234567"
4181// Set the maximum number of significant digits to 10 and retain the default values for other properties.
4182Decimal.set({ precision: 10, defaults: true })
4183let data3 : Decimal = data.add(0.5);
4184console.info("test Decimal set:" + data3.toString()); // "test Decimal set:1.73456789"
4185
4186// Usage of toExpNeg and toExpPos:
4187Decimal.set({ toExpNeg: -7 })
4188let x0 : Decimal = new Decimal(0.00000123) // x0:'0.00000123'
4189let x1 : Decimal = new Decimal(0.000000123) // x1:'1.23e-7'
4190
4191Decimal.set({ toExpPos: 2 })
4192let y0 : Decimal = new Decimal(12.3) // y0:'12.3'
4193let y1 : Decimal = new Decimal(123) // y1:'1.23e+2'
4194
4195// All data is expressed in scientific notation.
4196Decimal.set({ toExpPos: 0 })
4197
4198// Usage of minE and maxE:
4199Decimal.set({ minE: -500 })
4200let a0 : Decimal = new Decimal('1e-500') // a0:'1e-500'
4201let a1 : Decimal = new Decimal('9.9e-501') // a1:'0e0'
4202
4203Decimal.set({ minE: -3 })
4204let b0 : Decimal = new Decimal(0.001) // b0:'0.001'
4205let b1 : Decimal = new Decimal(0.0001) // b1:'0e0'
4206
4207Decimal.set({ maxE: 500 })
4208let c0 : Decimal = new Decimal('9.999e500') // c0:'9.999e+500'
4209let c1 : Decimal = new Decimal('1e501') // c1:'Infinity'
4210
4211Decimal.set({ maxE: 4 })
4212let d0 : Decimal = new Decimal(99999) // d0:'9.9999e+4'
4213let d1 : Decimal = new Decimal(100000) // d1:'Infinity'
4214```
4215
4216**Example 2**
4217
4218```ts
4219// /entry/src/main/ets/pages/test.ets
4220export function test(){
4221  let data : Decimal = new Decimal(1.2345678901234567);
4222  Decimal.set({
4223    precision: 5,
4224    rounding: 0,
4225    toExpNeg: -7,
4226    toExpPos: 7,
4227    maxE: 9e15,
4228    minE: -9e15,
4229    modulo: 1,
4230    crypto: false
4231  })
4232  let data1 : Decimal = data.add(0.5);
4233  console.info("test Decimal set:" + data1.toString()); // 'test Decimal set:1.7346'
4234}
4235```
4236
4237```ts
4238// /entry/src/main/ets/pages/Index.ets
4239import {test} from './test'
4240
4241let data : Decimal = new Decimal(1.2345678901234567);
4242Decimal.set({
4243  precision: 6,
4244  rounding: 1,
4245  toExpNeg: -7,
4246  toExpPos: 7,
4247  maxE: 9e15,
4248  minE: -9e15,
4249  modulo: 1,
4250  crypto: false
4251})
4252let data1 : Decimal = data.add(0.5);
4253console.info("test Decimal set:" + data1.toString()); // 'test Decimal set:1.73456'
4254test();
4255data1 = data1.add(0); // data1:'1.7346'
4256console.info("test Decimal set:" + data1.toString()); // 'test Decimal set:1.7346'
4257```
4258