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