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