1e41f4b71Sopenharmony_ci# @arkts.math.Decimal (高精度数学库Decimal)
2e41f4b71Sopenharmony_ci
3e41f4b71Sopenharmony_ciDecimal用于提供高精度数学库,主要用于提供高精度浮点运算能力。
4e41f4b71Sopenharmony_ci
5e41f4b71Sopenharmony_ci> **说明:**
6e41f4b71Sopenharmony_ci>
7e41f4b71Sopenharmony_ci> 本模块首批接口从API version 12开始支持。后续版本的新增接口,采用上角标单独标记接口的起始版本。
8e41f4b71Sopenharmony_ci
9e41f4b71Sopenharmony_ci
10e41f4b71Sopenharmony_ci## 导入模块
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_ci表示用于构建Decimal的参数类型。
21e41f4b71Sopenharmony_ci
22e41f4b71Sopenharmony_ci取值类型为下列类型中的并集。
23e41f4b71Sopenharmony_ci
24e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
25e41f4b71Sopenharmony_ci
26e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
27e41f4b71Sopenharmony_ci
28e41f4b71Sopenharmony_ci| 类型                | 说明                           |
29e41f4b71Sopenharmony_ci| ------------------- | ------------------------------ |
30e41f4b71Sopenharmony_ci| string              | 表示值类型为字符,可取任意值。 |
31e41f4b71Sopenharmony_ci| number              | 表示值类型为数字,可取任意值。 |
32e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 表示值类型为Decimal类型。      |
33e41f4b71Sopenharmony_ci
34e41f4b71Sopenharmony_ci## Rounding
35e41f4b71Sopenharmony_ci
36e41f4b71Sopenharmony_citype Rounding = 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8
37e41f4b71Sopenharmony_ci
38e41f4b71Sopenharmony_ci表示可设置的舍入类型。
39e41f4b71Sopenharmony_ci
40e41f4b71Sopenharmony_ci取值类型为下列类型中的并集。
41e41f4b71Sopenharmony_ci
42e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
43e41f4b71Sopenharmony_ci
44e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
45e41f4b71Sopenharmony_ci
46e41f4b71Sopenharmony_ci| 类型 | 说明                                                         |
47e41f4b71Sopenharmony_ci| ---- | ------------------------------------------------------------ |
48e41f4b71Sopenharmony_ci| 0    | 向远离零的方向舍入。与[Decimal.ROUND_UP](#常量)一致。        |
49e41f4b71Sopenharmony_ci| 1    | 向靠近零的方向舍入。与[Decimal.ROUND_DOWN](#常量)一致。      |
50e41f4b71Sopenharmony_ci| 2    | 向正无穷方向舍入。与[Decimal.ROUND_CEILING](#常量)一致。     |
51e41f4b71Sopenharmony_ci| 3    | 向负无穷方向舍入。与[Decimal.ROUND_FLOOR](#常量)一致。       |
52e41f4b71Sopenharmony_ci| 4    | 向最近的邻值舍入。如果距离相等,则远离零方向舍入。与[Decimal.ROUND_HALF_UP](#常量)一致。 |
53e41f4b71Sopenharmony_ci| 5    | 向最近的邻值舍入。如果距离相等,则靠近零方向舍入。与[Decimal.ROUND_HALF_DOWN](#常量)一致。 |
54e41f4b71Sopenharmony_ci| 6    | 向最近的邻值舍入。如果距离相等,则向偶数邻值舍入。与[Decimal.ROUND_HALF_EVEN](#常量)一致。 |
55e41f4b71Sopenharmony_ci| 7    | 向最近的邻值舍入。如果距离相等,则向正无穷方向舍入。与[Decimal.ROUND_HALF_CEILING](#常量)一致。 |
56e41f4b71Sopenharmony_ci| 8    | 向最近的邻值舍入。如果距离相等,则向负无穷方向舍入。与[Decimal.ROUND_HALF_FLOOR](#常量)一致。 |
57e41f4b71Sopenharmony_ci
58e41f4b71Sopenharmony_ci## Modulo
59e41f4b71Sopenharmony_ci
60e41f4b71Sopenharmony_citype Modulo = Rounding | 9
61e41f4b71Sopenharmony_ci
62e41f4b71Sopenharmony_ci表示可设置的取模方法舍入类型。
63e41f4b71Sopenharmony_ci
64e41f4b71Sopenharmony_ci取值类型为下列类型中的并集。
65e41f4b71Sopenharmony_ci
66e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
67e41f4b71Sopenharmony_ci
68e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
69e41f4b71Sopenharmony_ci
70e41f4b71Sopenharmony_ci| 类型                   | 说明                                                         |
71e41f4b71Sopenharmony_ci| ---------------------- | ------------------------------------------------------------ |
72e41f4b71Sopenharmony_ci| [Rounding](#rounding) | 模运算下的舍入类型。与[Rounding](#常量)表示的舍入模式相同。  |
73e41f4b71Sopenharmony_ci| 9                      | 余模运算下,余数始终为正。欧几里得除法。与[Decimal.EUCLID](#常量)一致。 |
74e41f4b71Sopenharmony_ci
75e41f4b71Sopenharmony_ci## DecimalConfig
76e41f4b71Sopenharmony_ci
77e41f4b71Sopenharmony_ci用于设置Decimal的配置属性,可使用[Decimal.set](#set)方法进行配置。
78e41f4b71Sopenharmony_ci
79e41f4b71Sopenharmony_ci### 属性
80e41f4b71Sopenharmony_ci
81e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
82e41f4b71Sopenharmony_ci
83e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
84e41f4b71Sopenharmony_ci
85e41f4b71Sopenharmony_ci| 名称      | 类型                   | 只读 | 必填 | 说明                                                         |
86e41f4b71Sopenharmony_ci| --------- | ---------------------- | ---- | ---- | ------------------------------------------------------------ |
87e41f4b71Sopenharmony_ci| precision | number                 | 否   | 否   | 运算结果的最大有效位数,取值范围为[1, 1e9],默认值为20。     |
88e41f4b71Sopenharmony_ci| rounding  | [Rounding](#rounding) | 否   | 否   | 舍入模式,取值范围为0到8的整数,默认值为4。                  |
89e41f4b71Sopenharmony_ci| toExpNeg  | number                 | 否   | 否   | 指数表示法的负指数值的极限值,若Decimal的负指数小于等于该值时,使用科学计数法表示,[toString](#tostring)方法中使用,取值范围为[-9e15, 0],默认值为-7。 |
90e41f4b71Sopenharmony_ci| toExpPos  | number                 | 否   | 否   | 指数表示法的正指数值的极限值,若Decimal的正指数大于等于该值时,使用科学计数法表示,[toString](#tostring)方法中使用,取值范围为[0, 9e15],默认值为20。 |
91e41f4b71Sopenharmony_ci| minE      | number                 | 否   | 否   | 负指数极限,若Decimal的指数值小于该值,会下溢到零,取值范围为[-9e15, 0],默认值为-9e15。 |
92e41f4b71Sopenharmony_ci| maxE      | number                 | 否   | 否   | 正指数极限,若Decimal的指数值大于该值,会溢出至无穷大,取值范围为[0, 9e15],默认值为9e15。 |
93e41f4b71Sopenharmony_ci| crypto    | boolean                | 否   | 否   | 确定是否使用加密安全伪随机数生成的值,用默认值为false。      |
94e41f4b71Sopenharmony_ci| modulo    | [Modulo](#modulo)      | 否   | 否   | 模计算时使用的舍入模式,取值范围为0到9的整数,默认值为1。    |
95e41f4b71Sopenharmony_ci| defaults  | boolean                | 否   | 否   | 表示未指定的属性是否被设置为默认值,true表示使用默认值,false表示不使用默认值,默认值为false。 |
96e41f4b71Sopenharmony_ci
97e41f4b71Sopenharmony_ci## Decimal
98e41f4b71Sopenharmony_ci
99e41f4b71Sopenharmony_ci任意精度的Decimal类型。
100e41f4b71Sopenharmony_ci
101e41f4b71Sopenharmony_ci### 属性
102e41f4b71Sopenharmony_ci
103e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
104e41f4b71Sopenharmony_ci
105e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
106e41f4b71Sopenharmony_ci
107e41f4b71Sopenharmony_ci| 名称 | 类型     | 只读 | 必填 | 说明                                      |
108e41f4b71Sopenharmony_ci| ---- | -------- | ---- | ---- | ----------------------------------------- |
109e41f4b71Sopenharmony_ci| d    | number[] | 是   | 是   | digits:表示Decimal数整数部分和小数部分。 |
110e41f4b71Sopenharmony_ci| e    | number   | 是   | 是   | exponent:表示Decimal数十进制指数的数目。 |
111e41f4b71Sopenharmony_ci| s    | number   | 是   | 是   | sign:表示Decimal数的符号位。             |
112e41f4b71Sopenharmony_ci
113e41f4b71Sopenharmony_ci### 常量
114e41f4b71Sopenharmony_ci
115e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
116e41f4b71Sopenharmony_ci
117e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
118e41f4b71Sopenharmony_ci
119e41f4b71Sopenharmony_ci| 名称               | 类型   | 值   | 说明                                                         |
120e41f4b71Sopenharmony_ci| ------------------ | ------ | ---- | ------------------------------------------------------------ |
121e41f4b71Sopenharmony_ci| ROUND_UP           | number | 0    | 向远离零的方向舍入。模运算下,如果被除数为负,则余数为正,否则为负。 |
122e41f4b71Sopenharmony_ci| ROUND_DOWN         | number | 1    | 向靠近零的方向舍入。模运算下,余数与被除数的符号相同,使用截断除法。 |
123e41f4b71Sopenharmony_ci| ROUND_CEILING      | number | 2    | 向正无穷方向舍入。                                           |
124e41f4b71Sopenharmony_ci| ROUND_FLOOR        | number | 3    | 向负无穷方向舍入。模运算下,余数与除数的符号相同。           |
125e41f4b71Sopenharmony_ci| ROUND_HALF_UP      | number | 4    | 向最近的邻值舍入。如果距离相等,则远离零方向舍入。           |
126e41f4b71Sopenharmony_ci| ROUND_HALF_DOWN    | number | 5    | 向最近的邻值舍入。如果距离相等,则靠近零方向舍入。           |
127e41f4b71Sopenharmony_ci| ROUND_HALF_EVEN    | number | 6    | 向最近的邻值舍入。如果距离相等,则向偶数邻值舍入。模运算下,IEEE 754 求余函数。 |
128e41f4b71Sopenharmony_ci| ROUND_HALF_CEILING | number | 7    | 向最近的邻值舍入。如果距离相等,则向正无穷方向舍入。         |
129e41f4b71Sopenharmony_ci| ROUND_HALF_FLOOR   | number | 8    | 向最近的邻值舍入。如果距离相等,则向负无穷方向舍入。         |
130e41f4b71Sopenharmony_ci| EUCLID             | number | 9    | 模运算下,余数始终为正。使用欧几里得除法:q = sign(x) * floor(a / abs(x))。 |
131e41f4b71Sopenharmony_ci
132e41f4b71Sopenharmony_ci### constructor
133e41f4b71Sopenharmony_ci
134e41f4b71Sopenharmony_ciconstructor(n: Value)
135e41f4b71Sopenharmony_ci
136e41f4b71Sopenharmony_ciDecimal的构造函数。
137e41f4b71Sopenharmony_ci
138e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
139e41f4b71Sopenharmony_ci
140e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
141e41f4b71Sopenharmony_ci
142e41f4b71Sopenharmony_ci**参数:**
143e41f4b71Sopenharmony_ci
144e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明                    |
145e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | ----------------------- |
146e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 构造Decimal时的初始值。 |
147e41f4b71Sopenharmony_ci
148e41f4b71Sopenharmony_ci**错误码:**
149e41f4b71Sopenharmony_ci
150e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
151e41f4b71Sopenharmony_ci
152e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
153e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
154e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
155e41f4b71Sopenharmony_ci
156e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal对象,其值为该Decimal的绝对值。
168e41f4b71Sopenharmony_ci
169e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
170e41f4b71Sopenharmony_ci
171e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
172e41f4b71Sopenharmony_ci
173e41f4b71Sopenharmony_ci**返回值:**
174e41f4b71Sopenharmony_ci
175e41f4b71Sopenharmony_ci| 类型                | 说明                                |
176e41f4b71Sopenharmony_ci| ------------------- | ----------------------------------- |
177e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回绝对值运算后的Decimal对象实例。 |
178e41f4b71Sopenharmony_ci
179e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal对象,其值为该Decimal向负无穷方向舍入得到的结果。
191e41f4b71Sopenharmony_ci
192e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
193e41f4b71Sopenharmony_ci
194e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
195e41f4b71Sopenharmony_ci
196e41f4b71Sopenharmony_ci**返回值:**
197e41f4b71Sopenharmony_ci
198e41f4b71Sopenharmony_ci| 类型                | 说明                            |
199e41f4b71Sopenharmony_ci| ------------------- | ------------------------------- |
200e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回舍入之后的Decimal对象实例。 |
201e41f4b71Sopenharmony_ci
202e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal对象,其值为该Decimal向正无穷方向舍入得到的结果。
214e41f4b71Sopenharmony_ci
215e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
216e41f4b71Sopenharmony_ci
217e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
218e41f4b71Sopenharmony_ci
219e41f4b71Sopenharmony_ci**返回值:**
220e41f4b71Sopenharmony_ci
221e41f4b71Sopenharmony_ci| 类型                | 说明                            |
222e41f4b71Sopenharmony_ci| ------------------- | ------------------------------- |
223e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回舍入之后的Decimal对象实例。 |
224e41f4b71Sopenharmony_ci
225e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal,其值是将此Decimal截断为整数部分。
237e41f4b71Sopenharmony_ci
238e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
239e41f4b71Sopenharmony_ci
240e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
241e41f4b71Sopenharmony_ci
242e41f4b71Sopenharmony_ci**返回值:**
243e41f4b71Sopenharmony_ci
244e41f4b71Sopenharmony_ci| 类型                | 说明                            |
245e41f4b71Sopenharmony_ci| ------------------- | ------------------------------- |
246e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回截断之后的Decimal对象实例。 |
247e41f4b71Sopenharmony_ci
248e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个值为将该Decimal的值限制在min到max范围内的Decimal对象。
260e41f4b71Sopenharmony_ci
261e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
262e41f4b71Sopenharmony_ci
263e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
264e41f4b71Sopenharmony_ci
265e41f4b71Sopenharmony_ci**参数:**
266e41f4b71Sopenharmony_ci
267e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明                     |
268e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | ------------------------ |
269e41f4b71Sopenharmony_ci| min    | [Value](#value) | 是   | 限制的最小值。包含该值。 |
270e41f4b71Sopenharmony_ci| max    | [Value](#value) | 是   | 限制的最大值。包含该值。 |
271e41f4b71Sopenharmony_ci
272e41f4b71Sopenharmony_ci**返回值:**
273e41f4b71Sopenharmony_ci
274e41f4b71Sopenharmony_ci| 类型                | 说明                              |
275e41f4b71Sopenharmony_ci| ------------------- | --------------------------------- |
276e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回符合范围内的Decimal对象实例。 |
277e41f4b71Sopenharmony_ci
278e41f4b71Sopenharmony_ci**错误码:**
279e41f4b71Sopenharmony_ci
280e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。
281e41f4b71Sopenharmony_ci
282e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
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**示例:**
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_ci返回一个新的Decimal,其值为该Decimal的值加上n。
301e41f4b71Sopenharmony_ci
302e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
303e41f4b71Sopenharmony_ci
304e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
305e41f4b71Sopenharmony_ci
306e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
307e41f4b71Sopenharmony_ci
308e41f4b71Sopenharmony_ci**参数:**
309e41f4b71Sopenharmony_ci
310e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明             |
311e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | ---------------- |
312e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 加法运算的加数。 |
313e41f4b71Sopenharmony_ci
314e41f4b71Sopenharmony_ci**返回值**:
315e41f4b71Sopenharmony_ci
316e41f4b71Sopenharmony_ci| 类型    | 说明                            |
317e41f4b71Sopenharmony_ci| ------- | ------------------------------- |
318e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回加法运算后的Decimal对象实例。 |
319e41f4b71Sopenharmony_ci
320e41f4b71Sopenharmony_ci**错误码:**
321e41f4b71Sopenharmony_ci
322e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
323e41f4b71Sopenharmony_ci
324e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
325e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
326e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
327e41f4b71Sopenharmony_ci
328e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal,其值为此Decimal的值减去n。
340e41f4b71Sopenharmony_ci
341e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
342e41f4b71Sopenharmony_ci
343e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
344e41f4b71Sopenharmony_ci
345e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
346e41f4b71Sopenharmony_ci
347e41f4b71Sopenharmony_ci**参数:**
348e41f4b71Sopenharmony_ci
349e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明             |
350e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | ---------------- |
351e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 减法运算的减数。 |
352e41f4b71Sopenharmony_ci
353e41f4b71Sopenharmony_ci**返回值:**
354e41f4b71Sopenharmony_ci
355e41f4b71Sopenharmony_ci| 类型    | 说明                            |
356e41f4b71Sopenharmony_ci| ------- | ------------------------------- |
357e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回减法运算后的Decimal对象实例。 |
358e41f4b71Sopenharmony_ci
359e41f4b71Sopenharmony_ci**错误码:**
360e41f4b71Sopenharmony_ci
361e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
362e41f4b71Sopenharmony_ci
363e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
364e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
365e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
366e41f4b71Sopenharmony_ci
367e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal,其值为Decimal乘以n。
379e41f4b71Sopenharmony_ci
380e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
381e41f4b71Sopenharmony_ci
382e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
383e41f4b71Sopenharmony_ci
384e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
385e41f4b71Sopenharmony_ci
386e41f4b71Sopenharmony_ci**参数:**
387e41f4b71Sopenharmony_ci
388e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明             |
389e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | ---------------- |
390e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 乘法运算的乘数。 |
391e41f4b71Sopenharmony_ci
392e41f4b71Sopenharmony_ci**返回值:**
393e41f4b71Sopenharmony_ci
394e41f4b71Sopenharmony_ci| 类型    | 说明                            |
395e41f4b71Sopenharmony_ci| ------- | ------------------------------- |
396e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回乘法运算后的Decimal对象实例。 |
397e41f4b71Sopenharmony_ci
398e41f4b71Sopenharmony_ci**错误码:**
399e41f4b71Sopenharmony_ci
400e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
401e41f4b71Sopenharmony_ci
402e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
403e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
404e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
405e41f4b71Sopenharmony_ci
406e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal,其值是此Decimal的值除以n。
418e41f4b71Sopenharmony_ci
419e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
420e41f4b71Sopenharmony_ci
421e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
422e41f4b71Sopenharmony_ci
423e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
424e41f4b71Sopenharmony_ci
425e41f4b71Sopenharmony_ci**参数:**
426e41f4b71Sopenharmony_ci
427e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明             |
428e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | ---------------- |
429e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 除法运算的除数。 |
430e41f4b71Sopenharmony_ci
431e41f4b71Sopenharmony_ci**返回值:**
432e41f4b71Sopenharmony_ci
433e41f4b71Sopenharmony_ci| 类型    | 说明                            |
434e41f4b71Sopenharmony_ci| ------- | ------------------------------- |
435e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回除法运算后的Decimal对象实例。 |
436e41f4b71Sopenharmony_ci
437e41f4b71Sopenharmony_ci**错误码:**
438e41f4b71Sopenharmony_ci
439e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
440e41f4b71Sopenharmony_ci
441e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
442e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
443e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
444e41f4b71Sopenharmony_ci
445e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal,其值是该Decimal除以n的模。
457e41f4b71Sopenharmony_ci
458e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
459e41f4b71Sopenharmony_ci
460e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
461e41f4b71Sopenharmony_ci
462e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
463e41f4b71Sopenharmony_ci
464e41f4b71Sopenharmony_ci**参数:**
465e41f4b71Sopenharmony_ci
466e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明             |
467e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | ---------------- |
468e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 取模运算的除数。 |
469e41f4b71Sopenharmony_ci
470e41f4b71Sopenharmony_ci**返回值:**
471e41f4b71Sopenharmony_ci
472e41f4b71Sopenharmony_ci| 类型    | 说明                            |
473e41f4b71Sopenharmony_ci| ------- | ------------------------------- |
474e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回取模运算后的Decimal对象实例。 |
475e41f4b71Sopenharmony_ci
476e41f4b71Sopenharmony_ci**错误码:**
477e41f4b71Sopenharmony_ci
478e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
479e41f4b71Sopenharmony_ci
480e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
481e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
482e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
483e41f4b71Sopenharmony_ci
484e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal,其值为该Decimal的平方根。
496e41f4b71Sopenharmony_ci
497e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
498e41f4b71Sopenharmony_ci
499e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
500e41f4b71Sopenharmony_ci
501e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
502e41f4b71Sopenharmony_ci
503e41f4b71Sopenharmony_ci**返回值:**
504e41f4b71Sopenharmony_ci
505e41f4b71Sopenharmony_ci| 类型    | 说明                              |
506e41f4b71Sopenharmony_ci| ------- | --------------------------------- |
507e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回平方根运算后的Decimal对象实例。 |
508e41f4b71Sopenharmony_ci
509e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal,其值是此Decimal值的立方根。
521e41f4b71Sopenharmony_ci
522e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
523e41f4b71Sopenharmony_ci
524e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
525e41f4b71Sopenharmony_ci
526e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
527e41f4b71Sopenharmony_ci
528e41f4b71Sopenharmony_ci**返回值:**
529e41f4b71Sopenharmony_ci
530e41f4b71Sopenharmony_ci| 类型    | 说明                              |
531e41f4b71Sopenharmony_ci| ------- | --------------------------------- |
532e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回立方根运算后的Decimal对象实例。 |
533e41f4b71Sopenharmony_ci
534e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal,它的值是这个Decimal的值的n次幂。
546e41f4b71Sopenharmony_ci
547e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
548e41f4b71Sopenharmony_ci
549e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
550e41f4b71Sopenharmony_ci
551e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
552e41f4b71Sopenharmony_ci
553e41f4b71Sopenharmony_ci**参数:**
554e41f4b71Sopenharmony_ci
555e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明             |
556e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | ---------------- |
557e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 幂运算的幂的值。 |
558e41f4b71Sopenharmony_ci
559e41f4b71Sopenharmony_ci**返回值:**
560e41f4b71Sopenharmony_ci
561e41f4b71Sopenharmony_ci| 类型    | 说明                          |
562e41f4b71Sopenharmony_ci| ------- | ----------------------------- |
563e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回幂运算后的Decimal对象实例。 |
564e41f4b71Sopenharmony_ci
565e41f4b71Sopenharmony_ci**错误码:**
566e41f4b71Sopenharmony_ci
567e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。
568e41f4b71Sopenharmony_ci
569e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
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**示例:**
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_ci返回一个新的Decimal,其值是该Decimal值的自然指数。
586e41f4b71Sopenharmony_ci
587e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
588e41f4b71Sopenharmony_ci
589e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
590e41f4b71Sopenharmony_ci
591e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
592e41f4b71Sopenharmony_ci
593e41f4b71Sopenharmony_ci**返回值:**
594e41f4b71Sopenharmony_ci
595e41f4b71Sopenharmony_ci| 类型                | 返回值                                |
596e41f4b71Sopenharmony_ci| ------------------- | ------------------------------------- |
597e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回自然指数运算后的Decimal对象实例。 |
598e41f4b71Sopenharmony_ci
599e41f4b71Sopenharmony_ci**错误码:**
600e41f4b71Sopenharmony_ci
601e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。
602e41f4b71Sopenharmony_ci
603e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                  |
604e41f4b71Sopenharmony_ci| -------- | ------------------------- |
605e41f4b71Sopenharmony_ci| 10200060 | Precision limit exceeded. |
606e41f4b71Sopenharmony_ci
607e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个值,以n为底的指定的对数运算的Decimal对象。
619e41f4b71Sopenharmony_ci
620e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
621e41f4b71Sopenharmony_ci
622e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
623e41f4b71Sopenharmony_ci
624e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
625e41f4b71Sopenharmony_ci
626e41f4b71Sopenharmony_ci**参数:**
627e41f4b71Sopenharmony_ci
628e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明               |
629e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | ------------------ |
630e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 对数计算的底数值。 |
631e41f4b71Sopenharmony_ci
632e41f4b71Sopenharmony_ci**返回值:**
633e41f4b71Sopenharmony_ci
634e41f4b71Sopenharmony_ci| 类型                | 说明                              |
635e41f4b71Sopenharmony_ci| ------------------- | --------------------------------- |
636e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回对数运算后的Decimal对象实例。 |
637e41f4b71Sopenharmony_ci
638e41f4b71Sopenharmony_ci**错误码**:
639e41f4b71Sopenharmony_ci
640e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。
641e41f4b71Sopenharmony_ci
642e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
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**示例:**
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_ci返回一个新的Decimal,其值是此Decimal值的自然对数。
659e41f4b71Sopenharmony_ci
660e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
661e41f4b71Sopenharmony_ci
662e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
663e41f4b71Sopenharmony_ci
664e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
665e41f4b71Sopenharmony_ci
666e41f4b71Sopenharmony_ci**返回值:**
667e41f4b71Sopenharmony_ci
668e41f4b71Sopenharmony_ci| 类型                | 说明                                  |
669e41f4b71Sopenharmony_ci| ------------------- | ------------------------------------- |
670e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回自然对数运算后的Decimal对象实例。 |
671e41f4b71Sopenharmony_ci
672e41f4b71Sopenharmony_ci**错误码:**
673e41f4b71Sopenharmony_ci
674e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。
675e41f4b71Sopenharmony_ci
676e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                  |
677e41f4b71Sopenharmony_ci| -------- | ------------------------- |
678e41f4b71Sopenharmony_ci| 10200060 | Precision limit exceeded. |
679e41f4b71Sopenharmony_ci
680e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal,其值是此Decimal的余弦值。
692e41f4b71Sopenharmony_ci
693e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
694e41f4b71Sopenharmony_ci
695e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
696e41f4b71Sopenharmony_ci
697e41f4b71Sopenharmony_ci**返回值:**
698e41f4b71Sopenharmony_ci
699e41f4b71Sopenharmony_ci| 类型                | 说明                              |
700e41f4b71Sopenharmony_ci| ------------------- | --------------------------------- |
701e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回计算余弦值的Decimal对象实例。 |
702e41f4b71Sopenharmony_ci
703e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal,其值是此Decimal的正弦值。
715e41f4b71Sopenharmony_ci
716e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
717e41f4b71Sopenharmony_ci
718e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
719e41f4b71Sopenharmony_ci
720e41f4b71Sopenharmony_ci**返回值:**
721e41f4b71Sopenharmony_ci
722e41f4b71Sopenharmony_ci| 类型                | 说明                              |
723e41f4b71Sopenharmony_ci| ------------------- | --------------------------------- |
724e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回计算正弦值的Decimal对象实例。 |
725e41f4b71Sopenharmony_ci
726e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal,其值是此Decimal的正切值。
738e41f4b71Sopenharmony_ci
739e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
740e41f4b71Sopenharmony_ci
741e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
742e41f4b71Sopenharmony_ci
743e41f4b71Sopenharmony_ci**返回值:**
744e41f4b71Sopenharmony_ci
745e41f4b71Sopenharmony_ci| 类型                | 说明                              |
746e41f4b71Sopenharmony_ci| ------------------- | --------------------------------- |
747e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回计算正切值的Decimal对象实例。 |
748e41f4b71Sopenharmony_ci
749e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal,其值是此Decimal的双曲余弦值。
761e41f4b71Sopenharmony_ci
762e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
763e41f4b71Sopenharmony_ci
764e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
765e41f4b71Sopenharmony_ci
766e41f4b71Sopenharmony_ci**返回值:**
767e41f4b71Sopenharmony_ci
768e41f4b71Sopenharmony_ci| 类型    | 说明                                |
769e41f4b71Sopenharmony_ci| ------- | ----------------------------------- |
770e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回计算双曲余弦值的Decimal对象实例。 |
771e41f4b71Sopenharmony_ci
772e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal,其值是此Decimal的双曲正弦值。
784e41f4b71Sopenharmony_ci
785e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
786e41f4b71Sopenharmony_ci
787e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
788e41f4b71Sopenharmony_ci
789e41f4b71Sopenharmony_ci**返回值:**
790e41f4b71Sopenharmony_ci
791e41f4b71Sopenharmony_ci| 类型    | 说明                                |
792e41f4b71Sopenharmony_ci| ------- | ----------------------------------- |
793e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回计算双曲正弦值的Decimal对象实例。 |
794e41f4b71Sopenharmony_ci
795e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal,其值是此Decimal的双曲正切值。
807e41f4b71Sopenharmony_ci
808e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
809e41f4b71Sopenharmony_ci
810e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
811e41f4b71Sopenharmony_ci
812e41f4b71Sopenharmony_ci**返回值:**
813e41f4b71Sopenharmony_ci
814e41f4b71Sopenharmony_ci| 类型    | 说明                                |
815e41f4b71Sopenharmony_ci| ------- | ----------------------------------- |
816e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回计算双曲正切值的Decimal对象实例。 |
817e41f4b71Sopenharmony_ci
818e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal,其值是此Decimal的反余弦值。
830e41f4b71Sopenharmony_ci
831e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
832e41f4b71Sopenharmony_ci
833e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
834e41f4b71Sopenharmony_ci
835e41f4b71Sopenharmony_ci**返回值:**
836e41f4b71Sopenharmony_ci
837e41f4b71Sopenharmony_ci| 类型    | 说明                              |
838e41f4b71Sopenharmony_ci| ------- | --------------------------------- |
839e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回计算反余弦值的Decimal对象实例。 |
840e41f4b71Sopenharmony_ci
841e41f4b71Sopenharmony_ci**错误码**:
842e41f4b71Sopenharmony_ci
843e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。
844e41f4b71Sopenharmony_ci
845e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                  |
846e41f4b71Sopenharmony_ci| -------- | ------------------------- |
847e41f4b71Sopenharmony_ci| 10200060 | Precision limit exceeded. |
848e41f4b71Sopenharmony_ci
849e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal,其值为此Decimal的反正弦值。
861e41f4b71Sopenharmony_ci
862e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
863e41f4b71Sopenharmony_ci
864e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
865e41f4b71Sopenharmony_ci
866e41f4b71Sopenharmony_ci**返回值:**
867e41f4b71Sopenharmony_ci
868e41f4b71Sopenharmony_ci| 类型    | 说明                              |
869e41f4b71Sopenharmony_ci| ------- | --------------------------------- |
870e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回计算反正弦值的Decimal对象实例。 |
871e41f4b71Sopenharmony_ci
872e41f4b71Sopenharmony_ci**错误码**:
873e41f4b71Sopenharmony_ci
874e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。
875e41f4b71Sopenharmony_ci
876e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                  |
877e41f4b71Sopenharmony_ci| -------- | ------------------------- |
878e41f4b71Sopenharmony_ci| 10200060 | Precision limit exceeded. |
879e41f4b71Sopenharmony_ci
880e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal,其值是此Decimal的反正切值。
892e41f4b71Sopenharmony_ci
893e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
894e41f4b71Sopenharmony_ci
895e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
896e41f4b71Sopenharmony_ci
897e41f4b71Sopenharmony_ci**返回值:**
898e41f4b71Sopenharmony_ci
899e41f4b71Sopenharmony_ci| 类型    | 说明                              |
900e41f4b71Sopenharmony_ci| ------- | --------------------------------- |
901e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回计算反正切值的Decimal对象实例。 |
902e41f4b71Sopenharmony_ci
903e41f4b71Sopenharmony_ci**错误码**:
904e41f4b71Sopenharmony_ci
905e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。
906e41f4b71Sopenharmony_ci
907e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                  |
908e41f4b71Sopenharmony_ci| -------- | ------------------------- |
909e41f4b71Sopenharmony_ci| 10200060 | Precision limit exceeded. |
910e41f4b71Sopenharmony_ci
911e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal,其值是此Decimal值的双曲余弦的倒数。
923e41f4b71Sopenharmony_ci
924e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
925e41f4b71Sopenharmony_ci
926e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
927e41f4b71Sopenharmony_ci
928e41f4b71Sopenharmony_ci**返回值:**
929e41f4b71Sopenharmony_ci
930e41f4b71Sopenharmony_ci| 类型                | 说明                                        |
931e41f4b71Sopenharmony_ci| ------------------- | ------------------------------------------- |
932e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回计算双曲余弦的倒数值的Decimal对象实例。 |
933e41f4b71Sopenharmony_ci
934e41f4b71Sopenharmony_ci**错误码**:
935e41f4b71Sopenharmony_ci
936e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。
937e41f4b71Sopenharmony_ci
938e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                  |
939e41f4b71Sopenharmony_ci| -------- | ------------------------- |
940e41f4b71Sopenharmony_ci| 10200060 | Precision limit exceeded. |
941e41f4b71Sopenharmony_ci
942e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal,其值是此Decimal值的双曲正弦的倒数。
954e41f4b71Sopenharmony_ci
955e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
956e41f4b71Sopenharmony_ci
957e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
958e41f4b71Sopenharmony_ci
959e41f4b71Sopenharmony_ci**返回值:**
960e41f4b71Sopenharmony_ci
961e41f4b71Sopenharmony_ci| 类型                | 说明                                        |
962e41f4b71Sopenharmony_ci| ------------------- | ------------------------------------------- |
963e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回计算双曲正弦的倒数值的Decimal对象实例。 |
964e41f4b71Sopenharmony_ci
965e41f4b71Sopenharmony_ci**错误码**:
966e41f4b71Sopenharmony_ci
967e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。
968e41f4b71Sopenharmony_ci
969e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                  |
970e41f4b71Sopenharmony_ci| -------- | ------------------------- |
971e41f4b71Sopenharmony_ci| 10200060 | Precision limit exceeded. |
972e41f4b71Sopenharmony_ci
973e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal,其值是此Decimal值的双曲正切的倒数。
985e41f4b71Sopenharmony_ci
986e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
987e41f4b71Sopenharmony_ci
988e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
989e41f4b71Sopenharmony_ci
990e41f4b71Sopenharmony_ci**返回值:**
991e41f4b71Sopenharmony_ci
992e41f4b71Sopenharmony_ci| 类型                | 说明                                        |
993e41f4b71Sopenharmony_ci| ------------------- | ------------------------------------------- |
994e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回计算双曲正切的倒数值的Decimal对象实例。 |
995e41f4b71Sopenharmony_ci
996e41f4b71Sopenharmony_ci**错误码**:
997e41f4b71Sopenharmony_ci
998e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。
999e41f4b71Sopenharmony_ci
1000e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                  |
1001e41f4b71Sopenharmony_ci| -------- | ------------------------- |
1002e41f4b71Sopenharmony_ci| 10200060 | Precision limit exceeded. |
1003e41f4b71Sopenharmony_ci
1004e41f4b71Sopenharmony_ci**示例:**
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_ciDecimal的比较方法。
1016e41f4b71Sopenharmony_ci
1017e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
1018e41f4b71Sopenharmony_ci
1019e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
1020e41f4b71Sopenharmony_ci
1021e41f4b71Sopenharmony_ci**参数:**
1022e41f4b71Sopenharmony_ci
1023e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明                  |
1024e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | --------------------- |
1025e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 待比较的值或Decimal。 |
1026e41f4b71Sopenharmony_ci
1027e41f4b71Sopenharmony_ci**返回值:**
1028e41f4b71Sopenharmony_ci
1029e41f4b71Sopenharmony_ci| 类型   | 说明                                                         |
1030e41f4b71Sopenharmony_ci| ------ | ------------------------------------------------------------ |
1031e41f4b71Sopenharmony_ci| number | 返回该Decimal与n的比较结果:<br>1:该Decimal大于比较值。<br/>-1:该Decimal小于比较值。<br/>0:该Decimal等于比较值。<br/>NaN:该Decimal与比较值有一个值为NaN。 |
1032e41f4b71Sopenharmony_ci
1033e41f4b71Sopenharmony_ci**错误码**:
1034e41f4b71Sopenharmony_ci
1035e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1036e41f4b71Sopenharmony_ci
1037e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
1038e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
1039e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
1040e41f4b71Sopenharmony_ci
1041e41f4b71Sopenharmony_ci**示例:**
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_ci返回该Decimal是否等于比较值。
1058e41f4b71Sopenharmony_ci
1059e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
1060e41f4b71Sopenharmony_ci
1061e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
1062e41f4b71Sopenharmony_ci
1063e41f4b71Sopenharmony_ci**参数:**
1064e41f4b71Sopenharmony_ci
1065e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明                  |
1066e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | --------------------- |
1067e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 待比较的值或Decimal。 |
1068e41f4b71Sopenharmony_ci
1069e41f4b71Sopenharmony_ci**返回值:**
1070e41f4b71Sopenharmony_ci
1071e41f4b71Sopenharmony_ci| 类型    | 说明                                             |
1072e41f4b71Sopenharmony_ci| ------- | ------------------------------------------------ |
1073e41f4b71Sopenharmony_ci| boolean | true表示该Decimal与比较值相等,其余情况为false。 |
1074e41f4b71Sopenharmony_ci
1075e41f4b71Sopenharmony_ci**错误码**:
1076e41f4b71Sopenharmony_ci
1077e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1078e41f4b71Sopenharmony_ci
1079e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
1080e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
1081e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
1082e41f4b71Sopenharmony_ci
1083e41f4b71Sopenharmony_ci**示例:**
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_ci返回该Decimal是否大于比较值。
1096e41f4b71Sopenharmony_ci
1097e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
1098e41f4b71Sopenharmony_ci
1099e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
1100e41f4b71Sopenharmony_ci
1101e41f4b71Sopenharmony_ci**参数:**
1102e41f4b71Sopenharmony_ci
1103e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明                  |
1104e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | --------------------- |
1105e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 待比较的值或Decimal。 |
1106e41f4b71Sopenharmony_ci
1107e41f4b71Sopenharmony_ci**返回值:**
1108e41f4b71Sopenharmony_ci
1109e41f4b71Sopenharmony_ci| 类型    | 说明                                           |
1110e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------- |
1111e41f4b71Sopenharmony_ci| boolean | true表示该Decimal大于比较值,其余情况为false。 |
1112e41f4b71Sopenharmony_ci
1113e41f4b71Sopenharmony_ci**错误码**:
1114e41f4b71Sopenharmony_ci
1115e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1116e41f4b71Sopenharmony_ci
1117e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
1118e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
1119e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
1120e41f4b71Sopenharmony_ci
1121e41f4b71Sopenharmony_ci**示例:**
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_ci返回该Decimal是否大于等于比较值。
1134e41f4b71Sopenharmony_ci
1135e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
1136e41f4b71Sopenharmony_ci
1137e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
1138e41f4b71Sopenharmony_ci
1139e41f4b71Sopenharmony_ci**参数:**
1140e41f4b71Sopenharmony_ci
1141e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明                  |
1142e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | --------------------- |
1143e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 待比较的值或Decimal。 |
1144e41f4b71Sopenharmony_ci
1145e41f4b71Sopenharmony_ci**返回值:**
1146e41f4b71Sopenharmony_ci
1147e41f4b71Sopenharmony_ci| 类型    | 说明                                               |
1148e41f4b71Sopenharmony_ci| ------- | -------------------------------------------------- |
1149e41f4b71Sopenharmony_ci| boolean | true表示该Decimal大于等于比较值,其余情况为false。 |
1150e41f4b71Sopenharmony_ci
1151e41f4b71Sopenharmony_ci**错误码**:
1152e41f4b71Sopenharmony_ci
1153e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1154e41f4b71Sopenharmony_ci
1155e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
1156e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
1157e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
1158e41f4b71Sopenharmony_ci
1159e41f4b71Sopenharmony_ci**示例:**
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_ci返回该Decimal是否小于比较值。
1172e41f4b71Sopenharmony_ci
1173e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
1174e41f4b71Sopenharmony_ci
1175e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
1176e41f4b71Sopenharmony_ci
1177e41f4b71Sopenharmony_ci**参数:**
1178e41f4b71Sopenharmony_ci
1179e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明                  |
1180e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | --------------------- |
1181e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 待比较的值或Decimal。 |
1182e41f4b71Sopenharmony_ci
1183e41f4b71Sopenharmony_ci**返回值:**
1184e41f4b71Sopenharmony_ci
1185e41f4b71Sopenharmony_ci| 类型    | 说明                                           |
1186e41f4b71Sopenharmony_ci| ------- | ---------------------------------------------- |
1187e41f4b71Sopenharmony_ci| boolean | true表示该Decimal小于比较值,其余情况为false。 |
1188e41f4b71Sopenharmony_ci
1189e41f4b71Sopenharmony_ci**错误码**:
1190e41f4b71Sopenharmony_ci
1191e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1192e41f4b71Sopenharmony_ci
1193e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
1194e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
1195e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
1196e41f4b71Sopenharmony_ci
1197e41f4b71Sopenharmony_ci**示例:**
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_ci返回该Decimal是否小于等于比较值。
1210e41f4b71Sopenharmony_ci
1211e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
1212e41f4b71Sopenharmony_ci
1213e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
1214e41f4b71Sopenharmony_ci
1215e41f4b71Sopenharmony_ci**参数:**
1216e41f4b71Sopenharmony_ci
1217e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明                  |
1218e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | --------------------- |
1219e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 待比较的值或Decimal。 |
1220e41f4b71Sopenharmony_ci
1221e41f4b71Sopenharmony_ci**返回值:**
1222e41f4b71Sopenharmony_ci
1223e41f4b71Sopenharmony_ci| 类型    | 说明                                               |
1224e41f4b71Sopenharmony_ci| ------- | -------------------------------------------------- |
1225e41f4b71Sopenharmony_ci| boolean | true表示该Decimal小于等于比较值,其余情况为false。 |
1226e41f4b71Sopenharmony_ci
1227e41f4b71Sopenharmony_ci**错误码**:
1228e41f4b71Sopenharmony_ci
1229e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1230e41f4b71Sopenharmony_ci
1231e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
1232e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
1233e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
1234e41f4b71Sopenharmony_ci
1235e41f4b71Sopenharmony_ci**示例:**
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_ci返回该Decimal是否为有限值。
1248e41f4b71Sopenharmony_ci
1249e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
1250e41f4b71Sopenharmony_ci
1251e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
1252e41f4b71Sopenharmony_ci
1253e41f4b71Sopenharmony_ci**返回值:**
1254e41f4b71Sopenharmony_ci
1255e41f4b71Sopenharmony_ci| 类型    | 说明                                         |
1256e41f4b71Sopenharmony_ci| ------- | -------------------------------------------- |
1257e41f4b71Sopenharmony_ci| boolean | true表示该Decimal为有限值,其余情况为false。 |
1258e41f4b71Sopenharmony_ci
1259e41f4b71Sopenharmony_ci**示例:**
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_ci返回该Decimal是否为整数。
1272e41f4b71Sopenharmony_ci
1273e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
1274e41f4b71Sopenharmony_ci
1275e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
1276e41f4b71Sopenharmony_ci
1277e41f4b71Sopenharmony_ci**返回值:**
1278e41f4b71Sopenharmony_ci
1279e41f4b71Sopenharmony_ci| 类型    | 说明                                       |
1280e41f4b71Sopenharmony_ci| ------- | ------------------------------------------ |
1281e41f4b71Sopenharmony_ci| boolean | true表示该Decimal为整数,其余情况为false。 |
1282e41f4b71Sopenharmony_ci
1283e41f4b71Sopenharmony_ci**示例:**
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_ci返回该Decimal是否为无效值。
1296e41f4b71Sopenharmony_ci
1297e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
1298e41f4b71Sopenharmony_ci
1299e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
1300e41f4b71Sopenharmony_ci
1301e41f4b71Sopenharmony_ci**返回值:**
1302e41f4b71Sopenharmony_ci
1303e41f4b71Sopenharmony_ci| 类型    | 说明                                      |
1304e41f4b71Sopenharmony_ci| ------- | ----------------------------------------- |
1305e41f4b71Sopenharmony_ci| boolean | true表示该Decimal为NaN,其余情况为false。 |
1306e41f4b71Sopenharmony_ci
1307e41f4b71Sopenharmony_ci**示例:**
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_ci返回该Decimal是否为负数。
1320e41f4b71Sopenharmony_ci
1321e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
1322e41f4b71Sopenharmony_ci
1323e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
1324e41f4b71Sopenharmony_ci
1325e41f4b71Sopenharmony_ci**返回值:**
1326e41f4b71Sopenharmony_ci
1327e41f4b71Sopenharmony_ci| 类型    | 说明                                       |
1328e41f4b71Sopenharmony_ci| ------- | ------------------------------------------ |
1329e41f4b71Sopenharmony_ci| boolean | true表示该Decimal为负数,其余情况为false。 |
1330e41f4b71Sopenharmony_ci
1331e41f4b71Sopenharmony_ci**示例:**
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_ci返回该Decimal是否为正数。
1348e41f4b71Sopenharmony_ci
1349e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
1350e41f4b71Sopenharmony_ci
1351e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
1352e41f4b71Sopenharmony_ci
1353e41f4b71Sopenharmony_ci**返回值:**
1354e41f4b71Sopenharmony_ci
1355e41f4b71Sopenharmony_ci| 类型    | 说明                                       |
1356e41f4b71Sopenharmony_ci| ------- | ------------------------------------------ |
1357e41f4b71Sopenharmony_ci| boolean | true表示该Decimal为正数,其余情况为false。 |
1358e41f4b71Sopenharmony_ci
1359e41f4b71Sopenharmony_ci**示例:**
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_ci返回该Decimal是否为0或是-0。
1376e41f4b71Sopenharmony_ci
1377e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
1378e41f4b71Sopenharmony_ci
1379e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
1380e41f4b71Sopenharmony_ci
1381e41f4b71Sopenharmony_ci**返回值:**
1382e41f4b71Sopenharmony_ci
1383e41f4b71Sopenharmony_ci| 类型    | 说明                                          |
1384e41f4b71Sopenharmony_ci| ------- | --------------------------------------------- |
1385e41f4b71Sopenharmony_ci| boolean | true表示该Decimal为0或是-0,其余情况为false。 |
1386e41f4b71Sopenharmony_ci
1387e41f4b71Sopenharmony_ci**示例:**
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_ci返回该Decimal除以n后获得的整数部分。
1400e41f4b71Sopenharmony_ci
1401e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
1402e41f4b71Sopenharmony_ci
1403e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
1404e41f4b71Sopenharmony_ci
1405e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
1406e41f4b71Sopenharmony_ci
1407e41f4b71Sopenharmony_ci**参数:**
1408e41f4b71Sopenharmony_ci
1409e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明           |
1410e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | -------------- |
1411e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 除法的除数值。 |
1412e41f4b71Sopenharmony_ci
1413e41f4b71Sopenharmony_ci**返回值:**
1414e41f4b71Sopenharmony_ci
1415e41f4b71Sopenharmony_ci| 类型                | 说明                                                         |
1416e41f4b71Sopenharmony_ci| ------------------- | ------------------------------------------------------------ |
1417e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回一个新的Decimal,其值是将该Decimal的值除以n值的整数部分。 |
1418e41f4b71Sopenharmony_ci
1419e41f4b71Sopenharmony_ci**错误码**:
1420e41f4b71Sopenharmony_ci
1421e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
1422e41f4b71Sopenharmony_ci
1423e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
1424e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
1425e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
1426e41f4b71Sopenharmony_ci
1427e41f4b71Sopenharmony_ci**示例:**
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_ciDecimal取反。
1441e41f4b71Sopenharmony_ci
1442e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
1443e41f4b71Sopenharmony_ci
1444e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
1445e41f4b71Sopenharmony_ci
1446e41f4b71Sopenharmony_ci**返回值:**
1447e41f4b71Sopenharmony_ci
1448e41f4b71Sopenharmony_ci| 类型                | 说明                                             |
1449e41f4b71Sopenharmony_ci| ------------------- | ------------------------------------------------ |
1450e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回一个新的Decimal,其值为该Decimal的值乘以-1。 |
1451e41f4b71Sopenharmony_ci
1452e41f4b71Sopenharmony_ci**示例:**
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_ci转换为二进制表示的字符串。
1465e41f4b71Sopenharmony_ci
1466e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
1467e41f4b71Sopenharmony_ci
1468e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
1469e41f4b71Sopenharmony_ci
1470e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
1471e41f4b71Sopenharmony_ci
1472e41f4b71Sopenharmony_ci**返回值:**
1473e41f4b71Sopenharmony_ci
1474e41f4b71Sopenharmony_ci| 类型   | 说明                     |
1475e41f4b71Sopenharmony_ci| ------ | ------------------------ |
1476e41f4b71Sopenharmony_ci| string | 返回二进制表示的字符串。 |
1477e41f4b71Sopenharmony_ci
1478e41f4b71Sopenharmony_ci**错误码:**
1479e41f4b71Sopenharmony_ci
1480e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。
1481e41f4b71Sopenharmony_ci
1482e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                          |
1483e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------- |
1484e41f4b71Sopenharmony_ci| 10200001 | The value of 'significantDigits' is out of range. |
1485e41f4b71Sopenharmony_ci
1486e41f4b71Sopenharmony_ci**示例:**
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_ci转换为二进制表示的字符串,可按照significantDigits设置有效数字。
1499e41f4b71Sopenharmony_ci
1500e41f4b71Sopenharmony_ci使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
1501e41f4b71Sopenharmony_ci
1502e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
1503e41f4b71Sopenharmony_ci
1504e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
1505e41f4b71Sopenharmony_ci
1506e41f4b71Sopenharmony_ci**参数:**
1507e41f4b71Sopenharmony_ci
1508e41f4b71Sopenharmony_ci| 参数名            | 类型   | 必填 | 说明                                             |
1509e41f4b71Sopenharmony_ci| ----------------- | ------ | ---- | ------------------------------------------------ |
1510e41f4b71Sopenharmony_ci| significantDigits | number | 是   | 转换时保留的有效数字,取值范围为[1, 1e9]的整数。 |
1511e41f4b71Sopenharmony_ci
1512e41f4b71Sopenharmony_ci**返回值:**
1513e41f4b71Sopenharmony_ci
1514e41f4b71Sopenharmony_ci| 类型   | 说明                     |
1515e41f4b71Sopenharmony_ci| ------ | ------------------------ |
1516e41f4b71Sopenharmony_ci| string | 返回二进制表示的字符串。 |
1517e41f4b71Sopenharmony_ci
1518e41f4b71Sopenharmony_ci**错误码:**
1519e41f4b71Sopenharmony_ci
1520e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。
1521e41f4b71Sopenharmony_ci
1522e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                          |
1523e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------- |
1524e41f4b71Sopenharmony_ci| 10200001 | The value of 'significantDigits' is out of range. |
1525e41f4b71Sopenharmony_ci
1526e41f4b71Sopenharmony_ci**示例:**
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_ci转换为二进制表示的字符串,可按照significantDigits设置有效数字,可按照rounding设置舍入模式。
1539e41f4b71Sopenharmony_ci
1540e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
1541e41f4b71Sopenharmony_ci
1542e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
1543e41f4b71Sopenharmony_ci
1544e41f4b71Sopenharmony_ci**参数:**
1545e41f4b71Sopenharmony_ci
1546e41f4b71Sopenharmony_ci| 参数名            | 类型                  | 必填 | 说明                                                      |
1547e41f4b71Sopenharmony_ci| ----------------- | --------------------- | ---- | --------------------------------------------------------- |
1548e41f4b71Sopenharmony_ci| significantDigits | number                | 是   | 转换时保留的有效数字,取值范围为[1, 1e9]的整数。          |
1549e41f4b71Sopenharmony_ci| rounding          | [Rounding](#rounding) | 是   | 转换时使用的舍入模式,取值范围参考[Rounding](#rounding)。 |
1550e41f4b71Sopenharmony_ci
1551e41f4b71Sopenharmony_ci**返回值:**
1552e41f4b71Sopenharmony_ci
1553e41f4b71Sopenharmony_ci| 类型   | 说明                     |
1554e41f4b71Sopenharmony_ci| ------ | ------------------------ |
1555e41f4b71Sopenharmony_ci| string | 返回二进制表示的字符串。 |
1556e41f4b71Sopenharmony_ci
1557e41f4b71Sopenharmony_ci**错误码:**
1558e41f4b71Sopenharmony_ci
1559e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。
1560e41f4b71Sopenharmony_ci
1561e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
1562e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
1563e41f4b71Sopenharmony_ci| 10200001 | The value of 'significantDigits \| rounding' is out of range. |
1564e41f4b71Sopenharmony_ci
1565e41f4b71Sopenharmony_ci**示例:**
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_ci转换为八进制表示的字符串。
1578e41f4b71Sopenharmony_ci
1579e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
1580e41f4b71Sopenharmony_ci
1581e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
1582e41f4b71Sopenharmony_ci
1583e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
1584e41f4b71Sopenharmony_ci
1585e41f4b71Sopenharmony_ci**返回值:**
1586e41f4b71Sopenharmony_ci
1587e41f4b71Sopenharmony_ci| 类型   | 说明                     |
1588e41f4b71Sopenharmony_ci| ------ | ------------------------ |
1589e41f4b71Sopenharmony_ci| string | 返回八进制表示的字符串。 |
1590e41f4b71Sopenharmony_ci
1591e41f4b71Sopenharmony_ci**示例:**
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_ci转换为八进制表示的字符串,可按照significantDigits设置有效数字。
1604e41f4b71Sopenharmony_ci
1605e41f4b71Sopenharmony_ci使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
1606e41f4b71Sopenharmony_ci
1607e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
1608e41f4b71Sopenharmony_ci
1609e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
1610e41f4b71Sopenharmony_ci
1611e41f4b71Sopenharmony_ci**参数:**
1612e41f4b71Sopenharmony_ci
1613e41f4b71Sopenharmony_ci| 参数名            | 类型   | 必填 | 说明                                             |
1614e41f4b71Sopenharmony_ci| ----------------- | ------ | ---- | ------------------------------------------------ |
1615e41f4b71Sopenharmony_ci| significantDigits | number | 是   | 转换时保留的有效数字,取值范围为[1, 1e9]的整数。 |
1616e41f4b71Sopenharmony_ci
1617e41f4b71Sopenharmony_ci**返回值:**
1618e41f4b71Sopenharmony_ci
1619e41f4b71Sopenharmony_ci| 类型   | 说明                     |
1620e41f4b71Sopenharmony_ci| ------ | ------------------------ |
1621e41f4b71Sopenharmony_ci| string | 返回八进制表示的字符串。 |
1622e41f4b71Sopenharmony_ci
1623e41f4b71Sopenharmony_ci**错误码:**
1624e41f4b71Sopenharmony_ci
1625e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。
1626e41f4b71Sopenharmony_ci
1627e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                          |
1628e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------- |
1629e41f4b71Sopenharmony_ci| 10200001 | The value of 'significantDigits' is out of range. |
1630e41f4b71Sopenharmony_ci
1631e41f4b71Sopenharmony_ci**示例:**
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_ci转换为八进制表示的字符串,可按照significantDigits设置有效数字,可按照rounding设置舍入模式。
1644e41f4b71Sopenharmony_ci
1645e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
1646e41f4b71Sopenharmony_ci
1647e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
1648e41f4b71Sopenharmony_ci
1649e41f4b71Sopenharmony_ci**参数:**
1650e41f4b71Sopenharmony_ci
1651e41f4b71Sopenharmony_ci| 参数名            | 类型                  | 必填 | 说明                                                      |
1652e41f4b71Sopenharmony_ci| ----------------- | --------------------- | ---- | --------------------------------------------------------- |
1653e41f4b71Sopenharmony_ci| significantDigits | number                | 是   | 转换时保留的有效数字,取值范围为[1, 1e9]的整数。          |
1654e41f4b71Sopenharmony_ci| rounding          | [Rounding](#rounding) | 是   | 转换时使用的舍入模式,取值范围参考[Rounding](#rounding)。 |
1655e41f4b71Sopenharmony_ci
1656e41f4b71Sopenharmony_ci**返回值:**
1657e41f4b71Sopenharmony_ci
1658e41f4b71Sopenharmony_ci| 类型   | 说明                     |
1659e41f4b71Sopenharmony_ci| ------ | ------------------------ |
1660e41f4b71Sopenharmony_ci| string | 返回八进制表示的字符串。 |
1661e41f4b71Sopenharmony_ci
1662e41f4b71Sopenharmony_ci**错误码:**
1663e41f4b71Sopenharmony_ci
1664e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。
1665e41f4b71Sopenharmony_ci
1666e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
1667e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
1668e41f4b71Sopenharmony_ci| 10200001 | The value of 'significantDigits \| rounding' is out of range. |
1669e41f4b71Sopenharmony_ci
1670e41f4b71Sopenharmony_ci**示例:**
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_ci转换为十六进制表示的字符串。
1683e41f4b71Sopenharmony_ci
1684e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
1685e41f4b71Sopenharmony_ci
1686e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
1687e41f4b71Sopenharmony_ci
1688e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
1689e41f4b71Sopenharmony_ci
1690e41f4b71Sopenharmony_ci**返回值:**
1691e41f4b71Sopenharmony_ci
1692e41f4b71Sopenharmony_ci| 类型   | 说明                       |
1693e41f4b71Sopenharmony_ci| ------ | -------------------------- |
1694e41f4b71Sopenharmony_ci| string | 返回十六进制表示的字符串。 |
1695e41f4b71Sopenharmony_ci
1696e41f4b71Sopenharmony_ci**示例:**
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_ci转换为十六进制表示的字符串,可按照significantDigits设置有效数字。
1709e41f4b71Sopenharmony_ci
1710e41f4b71Sopenharmony_ci使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
1711e41f4b71Sopenharmony_ci
1712e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
1713e41f4b71Sopenharmony_ci
1714e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
1715e41f4b71Sopenharmony_ci
1716e41f4b71Sopenharmony_ci**参数:**
1717e41f4b71Sopenharmony_ci
1718e41f4b71Sopenharmony_ci| 参数名            | 类型   | 必填 | 说明                                             |
1719e41f4b71Sopenharmony_ci| ----------------- | ------ | ---- | ------------------------------------------------ |
1720e41f4b71Sopenharmony_ci| significantDigits | number | 是   | 转换时保留的有效数字,取值范围为[1, 1e9]的整数。 |
1721e41f4b71Sopenharmony_ci
1722e41f4b71Sopenharmony_ci**返回值:**
1723e41f4b71Sopenharmony_ci
1724e41f4b71Sopenharmony_ci| 类型   | 说明                       |
1725e41f4b71Sopenharmony_ci| ------ | -------------------------- |
1726e41f4b71Sopenharmony_ci| string | 返回十六进制表示的字符串。 |
1727e41f4b71Sopenharmony_ci
1728e41f4b71Sopenharmony_ci**错误码:**
1729e41f4b71Sopenharmony_ci
1730e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。
1731e41f4b71Sopenharmony_ci
1732e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                          |
1733e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------- |
1734e41f4b71Sopenharmony_ci| 10200001 | The value of 'significantDigits' is out of range. |
1735e41f4b71Sopenharmony_ci
1736e41f4b71Sopenharmony_ci**示例:**
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_ci转换为十六进制表示的字符串,可按照significantDigits设置有效数字,可按照rounding设置舍入模式。
1749e41f4b71Sopenharmony_ci
1750e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
1751e41f4b71Sopenharmony_ci
1752e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
1753e41f4b71Sopenharmony_ci
1754e41f4b71Sopenharmony_ci**参数:**
1755e41f4b71Sopenharmony_ci
1756e41f4b71Sopenharmony_ci| 参数名            | 类型                  | 必填 | 说明                                                      |
1757e41f4b71Sopenharmony_ci| ----------------- | --------------------- | ---- | --------------------------------------------------------- |
1758e41f4b71Sopenharmony_ci| significantDigits | number                | 是   | 转换时保留的有效数字,取值范围为[1, 1e9]的整数。          |
1759e41f4b71Sopenharmony_ci| rounding          | [Rounding](#rounding) | 是   | 转换时使用的舍入模式,取值范围参考[Rounding](#rounding)。 |
1760e41f4b71Sopenharmony_ci
1761e41f4b71Sopenharmony_ci**返回值:**
1762e41f4b71Sopenharmony_ci
1763e41f4b71Sopenharmony_ci| 类型   | 说明                       |
1764e41f4b71Sopenharmony_ci| ------ | -------------------------- |
1765e41f4b71Sopenharmony_ci| string | 返回十六进制表示的字符串。 |
1766e41f4b71Sopenharmony_ci
1767e41f4b71Sopenharmony_ci**错误码:**
1768e41f4b71Sopenharmony_ci
1769e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。
1770e41f4b71Sopenharmony_ci
1771e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
1772e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
1773e41f4b71Sopenharmony_ci| 10200001 | The value of 'significantDigits \| rounding' is out of range. |
1774e41f4b71Sopenharmony_ci
1775e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个保留小数点后指定位数的Decimal对象,不进行小数的取舍。
1788e41f4b71Sopenharmony_ci
1789e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
1790e41f4b71Sopenharmony_ci
1791e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
1792e41f4b71Sopenharmony_ci
1793e41f4b71Sopenharmony_ci**返回值:**
1794e41f4b71Sopenharmony_ci
1795e41f4b71Sopenharmony_ci| 类型                | 说明                                        |
1796e41f4b71Sopenharmony_ci| ------------------- | ------------------------------------------- |
1797e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回一个新的Decimal,保留小数点后指定位数。 |
1798e41f4b71Sopenharmony_ci
1799e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个保留小数点后指定位数的Decimal对象,可按照decimalPlaces设置小数位数。
1812e41f4b71Sopenharmony_ci
1813e41f4b71Sopenharmony_ci使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
1814e41f4b71Sopenharmony_ci
1815e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
1816e41f4b71Sopenharmony_ci
1817e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
1818e41f4b71Sopenharmony_ci
1819e41f4b71Sopenharmony_ci**参数:**
1820e41f4b71Sopenharmony_ci
1821e41f4b71Sopenharmony_ci| 参数名        | 类型   | 必填 | 说明                                                     |
1822e41f4b71Sopenharmony_ci| ------------- | ------ | ---- | -------------------------------------------------------- |
1823e41f4b71Sopenharmony_ci| decimalPlaces | number | 是   | 转换时保留的小数点后有效位数,取值范围为[0, 1e9]的整数。 |
1824e41f4b71Sopenharmony_ci
1825e41f4b71Sopenharmony_ci**返回值:**
1826e41f4b71Sopenharmony_ci
1827e41f4b71Sopenharmony_ci| 类型                | 说明                                        |
1828e41f4b71Sopenharmony_ci| ------------------- | ------------------------------------------- |
1829e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回一个新的Decimal,保留小数点后指定位数。 |
1830e41f4b71Sopenharmony_ci
1831e41f4b71Sopenharmony_ci**错误码:**
1832e41f4b71Sopenharmony_ci
1833e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。
1834e41f4b71Sopenharmony_ci
1835e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                      |
1836e41f4b71Sopenharmony_ci| -------- | --------------------------------------------- |
1837e41f4b71Sopenharmony_ci| 10200001 | The value of 'decimalPlaces' is out of range. |
1838e41f4b71Sopenharmony_ci
1839e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个保留小数点后指定位数的Decimal对象,可按照decimalPlaces设置小数位数,可按照rounding设置舍入模式。
1852e41f4b71Sopenharmony_ci
1853e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
1854e41f4b71Sopenharmony_ci
1855e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
1856e41f4b71Sopenharmony_ci
1857e41f4b71Sopenharmony_ci**参数:**
1858e41f4b71Sopenharmony_ci
1859e41f4b71Sopenharmony_ci| 参数名        | 类型                  | 必填 | 说明                                                      |
1860e41f4b71Sopenharmony_ci| ------------- | --------------------- | ---- | --------------------------------------------------------- |
1861e41f4b71Sopenharmony_ci| decimalPlaces | number                | 是   | 转换时保留的小数点后有效位数,取值范围为[0, 1e9]的整数。  |
1862e41f4b71Sopenharmony_ci| rounding      | [Rounding](#rounding) | 是   | 转换时使用的舍入模式。取值范围参考[Rounding](#rounding)。 |
1863e41f4b71Sopenharmony_ci
1864e41f4b71Sopenharmony_ci**返回值:**
1865e41f4b71Sopenharmony_ci
1866e41f4b71Sopenharmony_ci| 类型                | 说明                                        |
1867e41f4b71Sopenharmony_ci| ------------------- | ------------------------------------------- |
1868e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回一个新的Decimal,保留小数点后指定位数。 |
1869e41f4b71Sopenharmony_ci
1870e41f4b71Sopenharmony_ci**错误码:**
1871e41f4b71Sopenharmony_ci
1872e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。
1873e41f4b71Sopenharmony_ci
1874e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                  |
1875e41f4b71Sopenharmony_ci| -------- | --------------------------------------------------------- |
1876e41f4b71Sopenharmony_ci| 10200001 | The value of 'decimalPlaces \| rounding' is out of range. |
1877e41f4b71Sopenharmony_ci
1878e41f4b71Sopenharmony_ci**示例:**
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_ci转换为按照指数表示法显示的字符串,不进行小数的取舍。
1892e41f4b71Sopenharmony_ci
1893e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
1894e41f4b71Sopenharmony_ci
1895e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
1896e41f4b71Sopenharmony_ci
1897e41f4b71Sopenharmony_ci**返回值:**
1898e41f4b71Sopenharmony_ci
1899e41f4b71Sopenharmony_ci| 类型   | 说明                             |
1900e41f4b71Sopenharmony_ci| ------ | -------------------------------- |
1901e41f4b71Sopenharmony_ci| string | 返回按照指数表示法显示的字符串。 |
1902e41f4b71Sopenharmony_ci
1903e41f4b71Sopenharmony_ci**示例:**
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_ci转换为按照指数表示法显示的字符串,可按照decimalPlaces设置小数位数。
1916e41f4b71Sopenharmony_ci
1917e41f4b71Sopenharmony_ci使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
1918e41f4b71Sopenharmony_ci
1919e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
1920e41f4b71Sopenharmony_ci
1921e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
1922e41f4b71Sopenharmony_ci
1923e41f4b71Sopenharmony_ci**参数:**
1924e41f4b71Sopenharmony_ci
1925e41f4b71Sopenharmony_ci| 参数名        | 类型   | 必填 | 说明                                                     |
1926e41f4b71Sopenharmony_ci| ------------- | ------ | ---- | -------------------------------------------------------- |
1927e41f4b71Sopenharmony_ci| decimalPlaces | number | 是   | 转换时保留的小数点后有效位数,取值范围为[0, 1e9]的整数。 |
1928e41f4b71Sopenharmony_ci
1929e41f4b71Sopenharmony_ci**返回值:**
1930e41f4b71Sopenharmony_ci
1931e41f4b71Sopenharmony_ci| 类型   | 说明                             |
1932e41f4b71Sopenharmony_ci| ------ | -------------------------------- |
1933e41f4b71Sopenharmony_ci| string | 返回按照指数表示法显示的字符串。 |
1934e41f4b71Sopenharmony_ci
1935e41f4b71Sopenharmony_ci**错误码:**
1936e41f4b71Sopenharmony_ci
1937e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。
1938e41f4b71Sopenharmony_ci
1939e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                      |
1940e41f4b71Sopenharmony_ci| -------- | --------------------------------------------- |
1941e41f4b71Sopenharmony_ci| 10200001 | The value of 'decimalPlaces' is out of range. |
1942e41f4b71Sopenharmony_ci
1943e41f4b71Sopenharmony_ci**示例:**
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_ci转换为按照指数表示法显示的字符串,可按照decimalPlaces设置小数位数,可按照rounding设置舍入模式。
1958e41f4b71Sopenharmony_ci
1959e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
1960e41f4b71Sopenharmony_ci
1961e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
1962e41f4b71Sopenharmony_ci
1963e41f4b71Sopenharmony_ci**参数:**
1964e41f4b71Sopenharmony_ci
1965e41f4b71Sopenharmony_ci| 参数名        | 类型                  | 必填 | 说明                                                      |
1966e41f4b71Sopenharmony_ci| ------------- | --------------------- | ---- | --------------------------------------------------------- |
1967e41f4b71Sopenharmony_ci| decimalPlaces | number                | 是   | 转换时保留的小数点后有效位数,取值范围为[0, 1e9]的整数。  |
1968e41f4b71Sopenharmony_ci| rounding      | [Rounding](#rounding) | 是   | 转换时使用的舍入模式,取值范围参考[Rounding](#rounding)。 |
1969e41f4b71Sopenharmony_ci
1970e41f4b71Sopenharmony_ci**返回值:**
1971e41f4b71Sopenharmony_ci
1972e41f4b71Sopenharmony_ci| 类型   | 说明                             |
1973e41f4b71Sopenharmony_ci| ------ | -------------------------------- |
1974e41f4b71Sopenharmony_ci| string | 返回按照指数表示法显示的字符串。 |
1975e41f4b71Sopenharmony_ci
1976e41f4b71Sopenharmony_ci**错误码:**
1977e41f4b71Sopenharmony_ci
1978e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。
1979e41f4b71Sopenharmony_ci
1980e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                  |
1981e41f4b71Sopenharmony_ci| -------- | --------------------------------------------------------- |
1982e41f4b71Sopenharmony_ci| 10200001 | The value of 'decimalPlaces \| rounding' is out of range. |
1983e41f4b71Sopenharmony_ci
1984e41f4b71Sopenharmony_ci**示例:**
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_ci转换为十进制定点模式表示的字符串,不进行小数的取舍。
1997e41f4b71Sopenharmony_ci
1998e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
1999e41f4b71Sopenharmony_ci
2000e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
2001e41f4b71Sopenharmony_ci
2002e41f4b71Sopenharmony_ci**返回值:**
2003e41f4b71Sopenharmony_ci
2004e41f4b71Sopenharmony_ci| 类型                | 说明                                             |
2005e41f4b71Sopenharmony_ci| ------------------- | ------------------------------------------------ |
2006e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回按照正常模式(十进制定点模式)表示的字符串。 |
2007e41f4b71Sopenharmony_ci
2008e41f4b71Sopenharmony_ci**示例:**
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_ci转换为十进制定点模式表示的字符串,可按照decimalPlaces设置小数位数。
2021e41f4b71Sopenharmony_ci
2022e41f4b71Sopenharmony_ci使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
2023e41f4b71Sopenharmony_ci
2024e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
2025e41f4b71Sopenharmony_ci
2026e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
2027e41f4b71Sopenharmony_ci
2028e41f4b71Sopenharmony_ci**参数:**
2029e41f4b71Sopenharmony_ci
2030e41f4b71Sopenharmony_ci| 参数名        | 类型   | 必填 | 说明                                                     |
2031e41f4b71Sopenharmony_ci| ------------- | ------ | ---- | -------------------------------------------------------- |
2032e41f4b71Sopenharmony_ci| decimalPlaces | number | 是   | 转换时保留的小数点后有效位数,取值范围为[0, 1e9]的整数。 |
2033e41f4b71Sopenharmony_ci
2034e41f4b71Sopenharmony_ci**返回值:**
2035e41f4b71Sopenharmony_ci
2036e41f4b71Sopenharmony_ci| 类型                | 说明                                             |
2037e41f4b71Sopenharmony_ci| ------------------- | ------------------------------------------------ |
2038e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回按照正常模式(十进制定点模式)表示的字符串。 |
2039e41f4b71Sopenharmony_ci
2040e41f4b71Sopenharmony_ci**错误码:**
2041e41f4b71Sopenharmony_ci
2042e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。
2043e41f4b71Sopenharmony_ci
2044e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                      |
2045e41f4b71Sopenharmony_ci| -------- | --------------------------------------------- |
2046e41f4b71Sopenharmony_ci| 10200001 | The value of 'decimalPlaces' is out of range. |
2047e41f4b71Sopenharmony_ci
2048e41f4b71Sopenharmony_ci**示例:**
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_ci转换为十进制定点模式表示的字符串,可按照decimalPlaces设置小数位数,可按照rounding设置舍入模式。
2063e41f4b71Sopenharmony_ci
2064e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
2065e41f4b71Sopenharmony_ci
2066e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
2067e41f4b71Sopenharmony_ci
2068e41f4b71Sopenharmony_ci**参数:**
2069e41f4b71Sopenharmony_ci
2070e41f4b71Sopenharmony_ci| 参数名        | 类型                  | 必填 | 说明                                                      |
2071e41f4b71Sopenharmony_ci| ------------- | --------------------- | ---- | --------------------------------------------------------- |
2072e41f4b71Sopenharmony_ci| decimalPlaces | number                | 是   | 转换时保留的小数点后有效位数,取值范围为[0, 1e9]的整数。  |
2073e41f4b71Sopenharmony_ci| rounding      | [Rounding](#rounding) | 是   | 转换时使用的舍入模式,取值范围参考[Rounding](#rounding)。 |
2074e41f4b71Sopenharmony_ci
2075e41f4b71Sopenharmony_ci**返回值:**
2076e41f4b71Sopenharmony_ci
2077e41f4b71Sopenharmony_ci| 类型                | 说明                                             |
2078e41f4b71Sopenharmony_ci| ------------------- | ------------------------------------------------ |
2079e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回按照正常模式(十进制定点模式)表示的字符串。 |
2080e41f4b71Sopenharmony_ci
2081e41f4b71Sopenharmony_ci**错误码:**
2082e41f4b71Sopenharmony_ci
2083e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。
2084e41f4b71Sopenharmony_ci
2085e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                  |
2086e41f4b71Sopenharmony_ci| -------- | --------------------------------------------------------- |
2087e41f4b71Sopenharmony_ci| 10200001 | The value of 'decimalPlaces \| rounding' is out of range. |
2088e41f4b71Sopenharmony_ci
2089e41f4b71Sopenharmony_ci**示例:**
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_ci转换为分数表示的数。
2102e41f4b71Sopenharmony_ci
2103e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
2104e41f4b71Sopenharmony_ci
2105e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
2106e41f4b71Sopenharmony_ci
2107e41f4b71Sopenharmony_ci**返回值:**
2108e41f4b71Sopenharmony_ci
2109e41f4b71Sopenharmony_ci| 类型                  | 说明                                                         |
2110e41f4b71Sopenharmony_ci| --------------------- | ------------------------------------------------------------ |
2111e41f4b71Sopenharmony_ci| [Decimal](#decimal)[] | 返回一个Decimal数组,该数组长度固定为2,其值表示为具有整数分子和整数分母的简单分数。且分子在前,分母在后。 |
2112e41f4b71Sopenharmony_ci
2113e41f4b71Sopenharmony_ci**示例:**
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_ci转换为分数表示的数,可以通过max_denominator设置最大分母值。
2126e41f4b71Sopenharmony_ci
2127e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
2128e41f4b71Sopenharmony_ci
2129e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
2130e41f4b71Sopenharmony_ci
2131e41f4b71Sopenharmony_ci**参数:**
2132e41f4b71Sopenharmony_ci
2133e41f4b71Sopenharmony_ci| 参数名          | 类型            | 必填 | 说明                     |
2134e41f4b71Sopenharmony_ci| --------------- | --------------- | ---- | ------------------------ |
2135e41f4b71Sopenharmony_ci| max_denominator | [Value](#value) | 是   | 分母的最大值。包含该值。 |
2136e41f4b71Sopenharmony_ci
2137e41f4b71Sopenharmony_ci**返回值:**
2138e41f4b71Sopenharmony_ci
2139e41f4b71Sopenharmony_ci| 类型                  | 说明                                                         |
2140e41f4b71Sopenharmony_ci| --------------------- | ------------------------------------------------------------ |
2141e41f4b71Sopenharmony_ci| [Decimal](#decimal)[] | 返回一个Decimal数组,该数组长度固定为2,其值表示为具有整数分子和整数分母的简单分数。且分子在前,分母在后。 |
2142e41f4b71Sopenharmony_ci
2143e41f4b71Sopenharmony_ci**错误码:**
2144e41f4b71Sopenharmony_ci
2145e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2146e41f4b71Sopenharmony_ci
2147e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
2148e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
2149e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
2150e41f4b71Sopenharmony_ci
2151e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal,该Decimal为指定值乘以一个倍数后与原Decimal最接近的值。
2168e41f4b71Sopenharmony_ci
2169e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
2170e41f4b71Sopenharmony_ci
2171e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
2172e41f4b71Sopenharmony_ci
2173e41f4b71Sopenharmony_ci**参数:**
2174e41f4b71Sopenharmony_ci
2175e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明           |
2176e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | -------------- |
2177e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 参考的指定值。 |
2178e41f4b71Sopenharmony_ci
2179e41f4b71Sopenharmony_ci**返回值:**
2180e41f4b71Sopenharmony_ci
2181e41f4b71Sopenharmony_ci| 类型    | 说明                                        |
2182e41f4b71Sopenharmony_ci| ------- | ------------------------------------------- |
2183e41f4b71Sopenharmony_ci| Decimal | 返回一个新的Decimal,指定值最接近的倍数值。 |
2184e41f4b71Sopenharmony_ci
2185e41f4b71Sopenharmony_ci**错误码:**
2186e41f4b71Sopenharmony_ci
2187e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。
2188e41f4b71Sopenharmony_ci
2189e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                 |
2190e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
2191e41f4b71Sopenharmony_ci| 10200001 | The value of 'rounding' is out of range. |
2192e41f4b71Sopenharmony_ci
2193e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal,该Decimal为指定值乘以一个倍数后与原Decimal最接近的值,可按照rounding设置舍入模式。
2206e41f4b71Sopenharmony_ci
2207e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
2208e41f4b71Sopenharmony_ci
2209e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
2210e41f4b71Sopenharmony_ci
2211e41f4b71Sopenharmony_ci**参数:**
2212e41f4b71Sopenharmony_ci
2213e41f4b71Sopenharmony_ci| 参数名   | 类型                  | 必填 | 说明                                                      |
2214e41f4b71Sopenharmony_ci| -------- | --------------------- | ---- | --------------------------------------------------------- |
2215e41f4b71Sopenharmony_ci| n        | [Value](#value)       | 是   | 参考的指定值。                                            |
2216e41f4b71Sopenharmony_ci| rounding | [Rounding](#rounding) | 是   | 转换时使用的舍入模式,取值范围参考[Rounding](#rounding)。 |
2217e41f4b71Sopenharmony_ci
2218e41f4b71Sopenharmony_ci**返回值:**
2219e41f4b71Sopenharmony_ci
2220e41f4b71Sopenharmony_ci| 类型                | 说明                                        |
2221e41f4b71Sopenharmony_ci| ------------------- | ------------------------------------------- |
2222e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回一个新的Decimal,指定值最接近的倍数值。 |
2223e41f4b71Sopenharmony_ci
2224e41f4b71Sopenharmony_ci**错误码:**
2225e41f4b71Sopenharmony_ci
2226e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。
2227e41f4b71Sopenharmony_ci
2228e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                 |
2229e41f4b71Sopenharmony_ci| -------- | ---------------------------------------- |
2230e41f4b71Sopenharmony_ci| 10200001 | The value of 'rounding' is out of range. |
2231e41f4b71Sopenharmony_ci
2232e41f4b71Sopenharmony_ci**示例:**
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_ci转换为字符串。
2245e41f4b71Sopenharmony_ci
2246e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
2247e41f4b71Sopenharmony_ci
2248e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
2249e41f4b71Sopenharmony_ci
2250e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
2251e41f4b71Sopenharmony_ci
2252e41f4b71Sopenharmony_ci**返回值:**
2253e41f4b71Sopenharmony_ci
2254e41f4b71Sopenharmony_ci| 类型   | 说明                              |
2255e41f4b71Sopenharmony_ci| ------ | --------------------------------- |
2256e41f4b71Sopenharmony_ci| string | 返回一个表示Decimal对象的字符串。 |
2257e41f4b71Sopenharmony_ci
2258e41f4b71Sopenharmony_ci**示例:**
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_ci转换为字符串,可按照significantDigits设置有效数字。
2271e41f4b71Sopenharmony_ci
2272e41f4b71Sopenharmony_ci使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
2273e41f4b71Sopenharmony_ci
2274e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
2275e41f4b71Sopenharmony_ci
2276e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
2277e41f4b71Sopenharmony_ci
2278e41f4b71Sopenharmony_ci**参数:**
2279e41f4b71Sopenharmony_ci
2280e41f4b71Sopenharmony_ci| 参数名            | 类型   | 必填 | 说明                   |
2281e41f4b71Sopenharmony_ci| ----------------- | ------ | ---- | ---------------------- |
2282e41f4b71Sopenharmony_ci| significantDigits | number | 是   | 转换时保留的有效数字。 |
2283e41f4b71Sopenharmony_ci
2284e41f4b71Sopenharmony_ci**返回值:**
2285e41f4b71Sopenharmony_ci
2286e41f4b71Sopenharmony_ci| 类型   | 说明                              |
2287e41f4b71Sopenharmony_ci| ------ | --------------------------------- |
2288e41f4b71Sopenharmony_ci| string | 返回一个表示Decimal对象的字符串。 |
2289e41f4b71Sopenharmony_ci
2290e41f4b71Sopenharmony_ci**错误码:**
2291e41f4b71Sopenharmony_ci
2292e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。
2293e41f4b71Sopenharmony_ci
2294e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                          |
2295e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------- |
2296e41f4b71Sopenharmony_ci| 10200001 | The value of 'significantDigits' is out of range. |
2297e41f4b71Sopenharmony_ci
2298e41f4b71Sopenharmony_ci**示例:**
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_ci转换为字符串,可按照significantDigits设置有效数字,可按照rounding设置舍入模式。
2312e41f4b71Sopenharmony_ci
2313e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
2314e41f4b71Sopenharmony_ci
2315e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
2316e41f4b71Sopenharmony_ci
2317e41f4b71Sopenharmony_ci**参数:**
2318e41f4b71Sopenharmony_ci
2319e41f4b71Sopenharmony_ci| 参数名            | 类型                  | 必填 | 说明                                                      |
2320e41f4b71Sopenharmony_ci| ----------------- | --------------------- | ---- | --------------------------------------------------------- |
2321e41f4b71Sopenharmony_ci| significantDigits | number                | 是   | 转换时保留的有效数字,取值范围为[1, 1e9]的整数。          |
2322e41f4b71Sopenharmony_ci| rounding          | [Rounding](#rounding) | 是   | 转换时使用的舍入模式,取值范围参考[Rounding](#rounding)。 |
2323e41f4b71Sopenharmony_ci
2324e41f4b71Sopenharmony_ci**返回值:**
2325e41f4b71Sopenharmony_ci
2326e41f4b71Sopenharmony_ci| 类型   | 说明                              |
2327e41f4b71Sopenharmony_ci| ------ | --------------------------------- |
2328e41f4b71Sopenharmony_ci| string | 返回一个表示Decimal对象的字符串。 |
2329e41f4b71Sopenharmony_ci
2330e41f4b71Sopenharmony_ci**错误码:**
2331e41f4b71Sopenharmony_ci
2332e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。
2333e41f4b71Sopenharmony_ci
2334e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
2335e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
2336e41f4b71Sopenharmony_ci| 10200001 | The value of 'significantDigits \|  rounding' is out of range. |
2337e41f4b71Sopenharmony_ci
2338e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个按照保留有效数字的转换的Decimal对象。
2351e41f4b71Sopenharmony_ci
2352e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
2353e41f4b71Sopenharmony_ci
2354e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
2355e41f4b71Sopenharmony_ci
2356e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
2357e41f4b71Sopenharmony_ci
2358e41f4b71Sopenharmony_ci**返回值:**
2359e41f4b71Sopenharmony_ci
2360e41f4b71Sopenharmony_ci| 类型    | 说明                                    |
2361e41f4b71Sopenharmony_ci| ------- | --------------------------------------- |
2362e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回一个保留有效数字后的Decimal对象实例。 |
2363e41f4b71Sopenharmony_ci
2364e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个按照保留有效数字的转换的Decimal对象,可按照significantDigits设置有效数字。
2377e41f4b71Sopenharmony_ci
2378e41f4b71Sopenharmony_ci使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
2379e41f4b71Sopenharmony_ci
2380e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
2381e41f4b71Sopenharmony_ci
2382e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
2383e41f4b71Sopenharmony_ci
2384e41f4b71Sopenharmony_ci**参数:**
2385e41f4b71Sopenharmony_ci
2386e41f4b71Sopenharmony_ci| 参数名            | 类型   | 必填 | 说明                   |
2387e41f4b71Sopenharmony_ci| ----------------- | ------ | ---- | ---------------------- |
2388e41f4b71Sopenharmony_ci| significantDigits | number | 是   | 转换时保留的有效数字。 |
2389e41f4b71Sopenharmony_ci
2390e41f4b71Sopenharmony_ci**返回值:**
2391e41f4b71Sopenharmony_ci
2392e41f4b71Sopenharmony_ci| 类型                | 说明                                      |
2393e41f4b71Sopenharmony_ci| ------------------- | ----------------------------------------- |
2394e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回一个保留有效数字后的Decimal对象实例。 |
2395e41f4b71Sopenharmony_ci
2396e41f4b71Sopenharmony_ci**错误码:**
2397e41f4b71Sopenharmony_ci
2398e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。
2399e41f4b71Sopenharmony_ci
2400e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                          |
2401e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------- |
2402e41f4b71Sopenharmony_ci| 10200001 | The value of 'significantDigits' is out of range. |
2403e41f4b71Sopenharmony_ci
2404e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个按照保留有效数字的转换的Decimal对象,可按照significantDigits设置有效数字,可按照rounding设置舍入模式。
2417e41f4b71Sopenharmony_ci
2418e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
2419e41f4b71Sopenharmony_ci
2420e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
2421e41f4b71Sopenharmony_ci
2422e41f4b71Sopenharmony_ci**参数:**
2423e41f4b71Sopenharmony_ci
2424e41f4b71Sopenharmony_ci| 参数名            | 类型                  | 必填 | 说明                                                      |
2425e41f4b71Sopenharmony_ci| ----------------- | --------------------- | ---- | --------------------------------------------------------- |
2426e41f4b71Sopenharmony_ci| significantDigits | number                | 是   | 转换时保留的有效数字,取值范围为[1, 1e9]的整数。          |
2427e41f4b71Sopenharmony_ci| rounding          | [Rounding](#rounding) | 是   | 转换时使用的舍入模式,取值范围参考[Rounding](#rounding)。 |
2428e41f4b71Sopenharmony_ci
2429e41f4b71Sopenharmony_ci**返回值:**
2430e41f4b71Sopenharmony_ci
2431e41f4b71Sopenharmony_ci| 类型                | 说明                                      |
2432e41f4b71Sopenharmony_ci| ------------------- | ----------------------------------------- |
2433e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回一个保留有效数字后的Decimal对象实例。 |
2434e41f4b71Sopenharmony_ci
2435e41f4b71Sopenharmony_ci**错误码:**
2436e41f4b71Sopenharmony_ci
2437e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。
2438e41f4b71Sopenharmony_ci
2439e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
2440e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
2441e41f4b71Sopenharmony_ci| 10200001 | The value of 'significantDigits \|  rounding' is out of range. |
2442e41f4b71Sopenharmony_ci
2443e41f4b71Sopenharmony_ci**示例:**
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_ci转换为number类型的值。
2456e41f4b71Sopenharmony_ci
2457e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
2458e41f4b71Sopenharmony_ci
2459e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
2460e41f4b71Sopenharmony_ci
2461e41f4b71Sopenharmony_ci**返回值:**
2462e41f4b71Sopenharmony_ci
2463e41f4b71Sopenharmony_ci| 类型   | 说明                            |
2464e41f4b71Sopenharmony_ci| ------ | ------------------------------- |
2465e41f4b71Sopenharmony_ci| number | 返回一个表示Decimal的number值。 |
2466e41f4b71Sopenharmony_ci
2467e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个字符串,表示此 Decimal 的值,如果此 Decimal 的正指数等于或大于[toExpPos](#decimalconfig),或负指数等于或小于[toExpNeg](#decimalconfig),则将返回指数表示法。
2480e41f4b71Sopenharmony_ci
2481e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
2482e41f4b71Sopenharmony_ci
2483e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
2484e41f4b71Sopenharmony_ci
2485e41f4b71Sopenharmony_ci**返回值:**
2486e41f4b71Sopenharmony_ci
2487e41f4b71Sopenharmony_ci| 类型   | 说明                          |
2488e41f4b71Sopenharmony_ci| ------ | ----------------------------- |
2489e41f4b71Sopenharmony_ci| string | 返回一个表示Decimal的字符串。 |
2490e41f4b71Sopenharmony_ci
2491e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个字符串,表示此 Decimal 的值,负零包含减号。
2513e41f4b71Sopenharmony_ci
2514e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
2515e41f4b71Sopenharmony_ci
2516e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
2517e41f4b71Sopenharmony_ci
2518e41f4b71Sopenharmony_ci**返回值:**
2519e41f4b71Sopenharmony_ci
2520e41f4b71Sopenharmony_ci| 类型   | 说明                          |
2521e41f4b71Sopenharmony_ci| ------ | ----------------------------- |
2522e41f4b71Sopenharmony_ci| string | 返回一个表示Decimal的字符串。 |
2523e41f4b71Sopenharmony_ci
2524e41f4b71Sopenharmony_ci**示例:**
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_ci返回Decimal对象的小数位数。
2537e41f4b71Sopenharmony_ci
2538e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
2539e41f4b71Sopenharmony_ci
2540e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
2541e41f4b71Sopenharmony_ci
2542e41f4b71Sopenharmony_ci**返回值:**
2543e41f4b71Sopenharmony_ci
2544e41f4b71Sopenharmony_ci| 类型   | 说明                        |
2545e41f4b71Sopenharmony_ci| ------ | --------------------------- |
2546e41f4b71Sopenharmony_ci| number | 返回Decimal对象的小数位数。 |
2547e41f4b71Sopenharmony_ci
2548e41f4b71Sopenharmony_ci**示例:**
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_ci返回Decimal对象的有效数字位数。
2561e41f4b71Sopenharmony_ci
2562e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
2563e41f4b71Sopenharmony_ci
2564e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
2565e41f4b71Sopenharmony_ci
2566e41f4b71Sopenharmony_ci**返回值:**
2567e41f4b71Sopenharmony_ci
2568e41f4b71Sopenharmony_ci| 类型   | 说明                        |
2569e41f4b71Sopenharmony_ci| ------ | --------------------------- |
2570e41f4b71Sopenharmony_ci| number | 返回Decimal对象的有效位数。 |
2571e41f4b71Sopenharmony_ci
2572e41f4b71Sopenharmony_ci**示例:**
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_ci返回Decimal对象的有效数字位数,通过includeZeros判断是否计算整数部分的尾随零。
2585e41f4b71Sopenharmony_ci
2586e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
2587e41f4b71Sopenharmony_ci
2588e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
2589e41f4b71Sopenharmony_ci
2590e41f4b71Sopenharmony_ci**参数:**
2591e41f4b71Sopenharmony_ci
2592e41f4b71Sopenharmony_ci| 参数名       | 类型    | 必填 | 说明                                                         |
2593e41f4b71Sopenharmony_ci| ------------ | ------- | ---- | ------------------------------------------------------------ |
2594e41f4b71Sopenharmony_ci| includeZeros | boolean | 是   | 是否计算整数部分尾随零。true表示计算整数部分尾随零,false表示不计算整数部分尾随零。 |
2595e41f4b71Sopenharmony_ci
2596e41f4b71Sopenharmony_ci**返回值:**
2597e41f4b71Sopenharmony_ci
2598e41f4b71Sopenharmony_ci| 类型   | 说明                        |
2599e41f4b71Sopenharmony_ci| ------ | --------------------------- |
2600e41f4b71Sopenharmony_ci| number | 返回Decimal对象的有效位数。 |
2601e41f4b71Sopenharmony_ci
2602e41f4b71Sopenharmony_ci**错误码:**
2603e41f4b71Sopenharmony_ci
2604e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[语言基础类库错误码](errorcode-utils.md)。
2605e41f4b71Sopenharmony_ci
2606e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                   |
2607e41f4b71Sopenharmony_ci| -------- | ------------------------------------------ |
2608e41f4b71Sopenharmony_ci| 10200001 | The value of includeZeros is out of range. |
2609e41f4b71Sopenharmony_ci
2610e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal对象,Decimal的值为参数n的绝对值。
2624e41f4b71Sopenharmony_ci
2625e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
2626e41f4b71Sopenharmony_ci
2627e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
2628e41f4b71Sopenharmony_ci
2629e41f4b71Sopenharmony_ci**参数:**
2630e41f4b71Sopenharmony_ci
2631e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明             |
2632e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | ---------------- |
2633e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 取绝对值的参数。 |
2634e41f4b71Sopenharmony_ci
2635e41f4b71Sopenharmony_ci**返回值:**
2636e41f4b71Sopenharmony_ci
2637e41f4b71Sopenharmony_ci| 类型                | 说明                                   |
2638e41f4b71Sopenharmony_ci| ------------------- | -------------------------------------- |
2639e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回一个值为参数n的绝对值的Decimal。 |
2640e41f4b71Sopenharmony_ci
2641e41f4b71Sopenharmony_ci**错误码:**
2642e41f4b71Sopenharmony_ci
2643e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2644e41f4b71Sopenharmony_ci
2645e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
2646e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
2647e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
2648e41f4b71Sopenharmony_ci
2649e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal对象,其值为该Decimal向负无穷方向舍入得到的结果。
2661e41f4b71Sopenharmony_ci
2662e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
2663e41f4b71Sopenharmony_ci
2664e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
2665e41f4b71Sopenharmony_ci
2666e41f4b71Sopenharmony_ci**参数:**
2667e41f4b71Sopenharmony_ci
2668e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明           |
2669e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | -------------- |
2670e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 需要舍入的值。 |
2671e41f4b71Sopenharmony_ci
2672e41f4b71Sopenharmony_ci**返回值:**
2673e41f4b71Sopenharmony_ci
2674e41f4b71Sopenharmony_ci| 类型                | 说明                            |
2675e41f4b71Sopenharmony_ci| ------------------- | ------------------------------- |
2676e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回舍入之后的Decimal对象实例。 |
2677e41f4b71Sopenharmony_ci
2678e41f4b71Sopenharmony_ci**错误码:**
2679e41f4b71Sopenharmony_ci
2680e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2681e41f4b71Sopenharmony_ci
2682e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
2683e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
2684e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
2685e41f4b71Sopenharmony_ci
2686e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal对象,其值为该Decimal向正无穷方向舍入得到的结果。
2698e41f4b71Sopenharmony_ci
2699e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
2700e41f4b71Sopenharmony_ci
2701e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
2702e41f4b71Sopenharmony_ci
2703e41f4b71Sopenharmony_ci**参数:**
2704e41f4b71Sopenharmony_ci
2705e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明           |
2706e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | -------------- |
2707e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 需要舍入的值。 |
2708e41f4b71Sopenharmony_ci
2709e41f4b71Sopenharmony_ci**返回值:**
2710e41f4b71Sopenharmony_ci
2711e41f4b71Sopenharmony_ci| 类型                | 说明                            |
2712e41f4b71Sopenharmony_ci| ------------------- | ------------------------------- |
2713e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回舍入之后的Decimal对象实例。 |
2714e41f4b71Sopenharmony_ci
2715e41f4b71Sopenharmony_ci**错误码:**
2716e41f4b71Sopenharmony_ci
2717e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2718e41f4b71Sopenharmony_ci
2719e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
2720e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
2721e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
2722e41f4b71Sopenharmony_ci
2723e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal,其值是将此Decimal截断为整数部分。
2735e41f4b71Sopenharmony_ci
2736e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
2737e41f4b71Sopenharmony_ci
2738e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
2739e41f4b71Sopenharmony_ci
2740e41f4b71Sopenharmony_ci**参数:**
2741e41f4b71Sopenharmony_ci
2742e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明           |
2743e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | -------------- |
2744e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 需要截断的值。 |
2745e41f4b71Sopenharmony_ci
2746e41f4b71Sopenharmony_ci**返回值:**
2747e41f4b71Sopenharmony_ci
2748e41f4b71Sopenharmony_ci| 类型                | 说明                            |
2749e41f4b71Sopenharmony_ci| ------------------- | ------------------------------- |
2750e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回截断之后的Decimal对象实例。 |
2751e41f4b71Sopenharmony_ci
2752e41f4b71Sopenharmony_ci**错误码:**
2753e41f4b71Sopenharmony_ci
2754e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2755e41f4b71Sopenharmony_ci
2756e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
2757e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
2758e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
2759e41f4b71Sopenharmony_ci
2760e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个值为将该Decimal的值限制在min到max范围内的Decimal对象。
2772e41f4b71Sopenharmony_ci
2773e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
2774e41f4b71Sopenharmony_ci
2775e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
2776e41f4b71Sopenharmony_ci
2777e41f4b71Sopenharmony_ci**参数:**
2778e41f4b71Sopenharmony_ci
2779e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明                     |
2780e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | ------------------------ |
2781e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 需要被限制的值。         |
2782e41f4b71Sopenharmony_ci| min    | [Value](#value) | 是   | 限制的最小值。包含该值。 |
2783e41f4b71Sopenharmony_ci| max    | [Value](#value) | 是   | 限制的最大值。包含该值。 |
2784e41f4b71Sopenharmony_ci
2785e41f4b71Sopenharmony_ci**返回值:**
2786e41f4b71Sopenharmony_ci
2787e41f4b71Sopenharmony_ci| 类型                | 说明                            |
2788e41f4b71Sopenharmony_ci| ------------------- | ------------------------------- |
2789e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回符合范围的Decimal对象实例。 |
2790e41f4b71Sopenharmony_ci
2791e41f4b71Sopenharmony_ci**错误码:**
2792e41f4b71Sopenharmony_ci
2793e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。
2794e41f4b71Sopenharmony_ci
2795e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
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**示例:**
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_ci返回一个值为x加y的和的Decimal对象。
2812e41f4b71Sopenharmony_ci
2813e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
2814e41f4b71Sopenharmony_ci
2815e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
2816e41f4b71Sopenharmony_ci
2817e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
2818e41f4b71Sopenharmony_ci
2819e41f4b71Sopenharmony_ci**参数:**
2820e41f4b71Sopenharmony_ci
2821e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明               |
2822e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | ------------------ |
2823e41f4b71Sopenharmony_ci| x      | [Value](#value) | 是   | 加法的一个加数。   |
2824e41f4b71Sopenharmony_ci| y      | [Value](#value) | 是   | 加法的另一个加数。 |
2825e41f4b71Sopenharmony_ci
2826e41f4b71Sopenharmony_ci**返回值:**
2827e41f4b71Sopenharmony_ci
2828e41f4b71Sopenharmony_ci| 类型                | 说明                              |
2829e41f4b71Sopenharmony_ci| ------------------- | --------------------------------- |
2830e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回加法运算后的Decimal对象实例。 |
2831e41f4b71Sopenharmony_ci
2832e41f4b71Sopenharmony_ci**错误码:**
2833e41f4b71Sopenharmony_ci
2834e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2835e41f4b71Sopenharmony_ci
2836e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
2837e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
2838e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
2839e41f4b71Sopenharmony_ci
2840e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个值为数组的和的Decimal对象。
2852e41f4b71Sopenharmony_ci
2853e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
2854e41f4b71Sopenharmony_ci
2855e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
2856e41f4b71Sopenharmony_ci
2857e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
2858e41f4b71Sopenharmony_ci
2859e41f4b71Sopenharmony_ci**参数:**
2860e41f4b71Sopenharmony_ci
2861e41f4b71Sopenharmony_ci| 参数名 | 类型              | 必填 | 说明         |
2862e41f4b71Sopenharmony_ci| ------ | ----------------- | ---- | ------------ |
2863e41f4b71Sopenharmony_ci| n      | [Value](#value)[] | 是   | 加数的数组。 |
2864e41f4b71Sopenharmony_ci
2865e41f4b71Sopenharmony_ci**返回值:**
2866e41f4b71Sopenharmony_ci
2867e41f4b71Sopenharmony_ci| 类型                | 说明                              |
2868e41f4b71Sopenharmony_ci| ------------------- | --------------------------------- |
2869e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回加法运算后的Decimal对象实例。 |
2870e41f4b71Sopenharmony_ci
2871e41f4b71Sopenharmony_ci**错误码:**
2872e41f4b71Sopenharmony_ci
2873e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2874e41f4b71Sopenharmony_ci
2875e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
2876e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
2877e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
2878e41f4b71Sopenharmony_ci
2879e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个值为x减y的差的Decimal对象。
2891e41f4b71Sopenharmony_ci
2892e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
2893e41f4b71Sopenharmony_ci
2894e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
2895e41f4b71Sopenharmony_ci
2896e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
2897e41f4b71Sopenharmony_ci
2898e41f4b71Sopenharmony_ci**参数:**
2899e41f4b71Sopenharmony_ci
2900e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明           |
2901e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | -------------- |
2902e41f4b71Sopenharmony_ci| x      | [Value](#value) | 是   | 减法的被减数。 |
2903e41f4b71Sopenharmony_ci| y      | [Value](#value) | 是   | 减法的减数。   |
2904e41f4b71Sopenharmony_ci
2905e41f4b71Sopenharmony_ci**返回值:**
2906e41f4b71Sopenharmony_ci
2907e41f4b71Sopenharmony_ci| 类型                | 说明                              |
2908e41f4b71Sopenharmony_ci| ------------------- | --------------------------------- |
2909e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回减法运算后的Decimal对象实例。 |
2910e41f4b71Sopenharmony_ci
2911e41f4b71Sopenharmony_ci**错误码:**
2912e41f4b71Sopenharmony_ci
2913e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2914e41f4b71Sopenharmony_ci
2915e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
2916e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
2917e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
2918e41f4b71Sopenharmony_ci
2919e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个值为x乘以y的积的Decimal对象。
2931e41f4b71Sopenharmony_ci
2932e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
2933e41f4b71Sopenharmony_ci
2934e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
2935e41f4b71Sopenharmony_ci
2936e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
2937e41f4b71Sopenharmony_ci
2938e41f4b71Sopenharmony_ci**参数:**
2939e41f4b71Sopenharmony_ci
2940e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明           |
2941e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | -------------- |
2942e41f4b71Sopenharmony_ci| x      | [Value](#value) | 是   | 乘法的被乘数。 |
2943e41f4b71Sopenharmony_ci| y      | [Value](#value) | 是   | 乘法的乘数。   |
2944e41f4b71Sopenharmony_ci
2945e41f4b71Sopenharmony_ci**返回值:**
2946e41f4b71Sopenharmony_ci
2947e41f4b71Sopenharmony_ci| 类型                | 说明                              |
2948e41f4b71Sopenharmony_ci| ------------------- | --------------------------------- |
2949e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回乘法运算后的Decimal对象实例。 |
2950e41f4b71Sopenharmony_ci
2951e41f4b71Sopenharmony_ci**错误码:**
2952e41f4b71Sopenharmony_ci
2953e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2954e41f4b71Sopenharmony_ci
2955e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
2956e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
2957e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
2958e41f4b71Sopenharmony_ci
2959e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个值为x除以y的商的Decimal对象。
2971e41f4b71Sopenharmony_ci
2972e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
2973e41f4b71Sopenharmony_ci
2974e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
2975e41f4b71Sopenharmony_ci
2976e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
2977e41f4b71Sopenharmony_ci
2978e41f4b71Sopenharmony_ci**参数:**
2979e41f4b71Sopenharmony_ci
2980e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明           |
2981e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | -------------- |
2982e41f4b71Sopenharmony_ci| x      | [Value](#value) | 是   | 除法的被除数。 |
2983e41f4b71Sopenharmony_ci| y      | [Value](#value) | 是   | 除法的除数。   |
2984e41f4b71Sopenharmony_ci
2985e41f4b71Sopenharmony_ci**返回值:**
2986e41f4b71Sopenharmony_ci
2987e41f4b71Sopenharmony_ci| 类型                | 说明                              |
2988e41f4b71Sopenharmony_ci| ------------------- | --------------------------------- |
2989e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回除法运算后的Decimal对象实例。 |
2990e41f4b71Sopenharmony_ci
2991e41f4b71Sopenharmony_ci**错误码:**
2992e41f4b71Sopenharmony_ci
2993e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
2994e41f4b71Sopenharmony_ci
2995e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
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**示例:**
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_ci返回一个新的Decimal对象,其值是x除以y的模。
3012e41f4b71Sopenharmony_ci
3013e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
3014e41f4b71Sopenharmony_ci
3015e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
3016e41f4b71Sopenharmony_ci
3017e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
3018e41f4b71Sopenharmony_ci
3019e41f4b71Sopenharmony_ci**参数:**
3020e41f4b71Sopenharmony_ci
3021e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明               |
3022e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | ------------------ |
3023e41f4b71Sopenharmony_ci| x      | [Value](#value) | 是   | 模除运算的被除数。 |
3024e41f4b71Sopenharmony_ci| y      | [Value](#value) | 是   | 模除运算的除数。   |
3025e41f4b71Sopenharmony_ci
3026e41f4b71Sopenharmony_ci**返回值:**
3027e41f4b71Sopenharmony_ci
3028e41f4b71Sopenharmony_ci| 类型                | 说明                              |
3029e41f4b71Sopenharmony_ci| ------------------- | --------------------------------- |
3030e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回模除运算后的Decimal对象实例。 |
3031e41f4b71Sopenharmony_ci
3032e41f4b71Sopenharmony_ci**错误码:**
3033e41f4b71Sopenharmony_ci
3034e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3035e41f4b71Sopenharmony_ci
3036e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
3037e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
3038e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
3039e41f4b71Sopenharmony_ci
3040e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个值为n的平方根的Decimal对象。
3052e41f4b71Sopenharmony_ci
3053e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
3054e41f4b71Sopenharmony_ci
3055e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
3056e41f4b71Sopenharmony_ci
3057e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
3058e41f4b71Sopenharmony_ci
3059e41f4b71Sopenharmony_ci**参数:**
3060e41f4b71Sopenharmony_ci
3061e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明           |
3062e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | -------------- |
3063e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 取平方根的值。 |
3064e41f4b71Sopenharmony_ci
3065e41f4b71Sopenharmony_ci**返回值:**
3066e41f4b71Sopenharmony_ci
3067e41f4b71Sopenharmony_ci| 类型                | 说明                                |
3068e41f4b71Sopenharmony_ci| ------------------- | ----------------------------------- |
3069e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回平方根运算后的Decimal对象实例。 |
3070e41f4b71Sopenharmony_ci
3071e41f4b71Sopenharmony_ci**错误码:**
3072e41f4b71Sopenharmony_ci
3073e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3074e41f4b71Sopenharmony_ci
3075e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
3076e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
3077e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
3078e41f4b71Sopenharmony_ci
3079e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个值为n的立方根的Decimal对象。
3091e41f4b71Sopenharmony_ci
3092e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
3093e41f4b71Sopenharmony_ci
3094e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
3095e41f4b71Sopenharmony_ci
3096e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
3097e41f4b71Sopenharmony_ci
3098e41f4b71Sopenharmony_ci**参数:**
3099e41f4b71Sopenharmony_ci
3100e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明           |
3101e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | -------------- |
3102e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 取立方根的值。 |
3103e41f4b71Sopenharmony_ci
3104e41f4b71Sopenharmony_ci**返回值:**
3105e41f4b71Sopenharmony_ci
3106e41f4b71Sopenharmony_ci| 类型                | 说明                                |
3107e41f4b71Sopenharmony_ci| ------------------- | ----------------------------------- |
3108e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回立方根运算后的Decimal对象实例。 |
3109e41f4b71Sopenharmony_ci
3110e41f4b71Sopenharmony_ci**错误码:**
3111e41f4b71Sopenharmony_ci
3112e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3113e41f4b71Sopenharmony_ci
3114e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
3115e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
3116e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
3117e41f4b71Sopenharmony_ci
3118e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个值为base的exponent次幂的Decimal对象,按照[DecimalConfig.precision](#decimalconfig)设置有效位数,按照[DecimalConfig.rounding](#decimalconfig)设置舍入模式。
3130e41f4b71Sopenharmony_ci
3131e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
3132e41f4b71Sopenharmony_ci
3133e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
3134e41f4b71Sopenharmony_ci
3135e41f4b71Sopenharmony_ci**参数:**
3136e41f4b71Sopenharmony_ci
3137e41f4b71Sopenharmony_ci| 参数名   | 类型            | 必填 | 说明               |
3138e41f4b71Sopenharmony_ci| -------- | --------------- | ---- | ------------------ |
3139e41f4b71Sopenharmony_ci| base     | [Value](#value) | 是   | 幂运算的底数的值。 |
3140e41f4b71Sopenharmony_ci| exponent | [Value](#value) | 是   | 幂运算的幂的值。   |
3141e41f4b71Sopenharmony_ci
3142e41f4b71Sopenharmony_ci**返回值:**
3143e41f4b71Sopenharmony_ci
3144e41f4b71Sopenharmony_ci| 类型                | 说明                            |
3145e41f4b71Sopenharmony_ci| ------------------- | ------------------------------- |
3146e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回幂运算后的Decimal对象实例。 |
3147e41f4b71Sopenharmony_ci
3148e41f4b71Sopenharmony_ci**错误码:**
3149e41f4b71Sopenharmony_ci
3150e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。
3151e41f4b71Sopenharmony_ci
3152e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
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**示例:**
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_ci返回一个值为n的自然指数的Decimal对象。
3169e41f4b71Sopenharmony_ci
3170e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
3171e41f4b71Sopenharmony_ci
3172e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
3173e41f4b71Sopenharmony_ci
3174e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
3175e41f4b71Sopenharmony_ci
3176e41f4b71Sopenharmony_ci**参数:**
3177e41f4b71Sopenharmony_ci
3178e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明                 |
3179e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | -------------------- |
3180e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 需要求自然指数的值。 |
3181e41f4b71Sopenharmony_ci
3182e41f4b71Sopenharmony_ci**返回值:**
3183e41f4b71Sopenharmony_ci
3184e41f4b71Sopenharmony_ci| 类型                | 说明                                  |
3185e41f4b71Sopenharmony_ci| ------------------- | ------------------------------------- |
3186e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回自然指数运算后的Decimal对象实例。 |
3187e41f4b71Sopenharmony_ci
3188e41f4b71Sopenharmony_ci**错误码:**
3189e41f4b71Sopenharmony_ci
3190e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。
3191e41f4b71Sopenharmony_ci
3192e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
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**示例:**
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_ci返回一个值为以base为底n的对数的Decimal对象。
3209e41f4b71Sopenharmony_ci
3210e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
3211e41f4b71Sopenharmony_ci
3212e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
3213e41f4b71Sopenharmony_ci
3214e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
3215e41f4b71Sopenharmony_ci
3216e41f4b71Sopenharmony_ci**参数:**
3217e41f4b71Sopenharmony_ci
3218e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明             |
3219e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | ---------------- |
3220e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 对数运算的真数。 |
3221e41f4b71Sopenharmony_ci| base   | [Value](#value) | 是   | 对数运算的底。   |
3222e41f4b71Sopenharmony_ci
3223e41f4b71Sopenharmony_ci**返回值:**
3224e41f4b71Sopenharmony_ci
3225e41f4b71Sopenharmony_ci| 类型                | 说明                              |
3226e41f4b71Sopenharmony_ci| ------------------- | --------------------------------- |
3227e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回对数运算后的Decimal对象实例。 |
3228e41f4b71Sopenharmony_ci
3229e41f4b71Sopenharmony_ci**错误码:**
3230e41f4b71Sopenharmony_ci
3231e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。
3232e41f4b71Sopenharmony_ci
3233e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
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**示例:**
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_ci返回一个值为n的自然对数的Decimal对象。
3250e41f4b71Sopenharmony_ci
3251e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
3252e41f4b71Sopenharmony_ci
3253e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
3254e41f4b71Sopenharmony_ci
3255e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
3256e41f4b71Sopenharmony_ci
3257e41f4b71Sopenharmony_ci**参数:**
3258e41f4b71Sopenharmony_ci
3259e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明             |
3260e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | ---------------- |
3261e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 对数运算的真数。 |
3262e41f4b71Sopenharmony_ci
3263e41f4b71Sopenharmony_ci**返回值:**
3264e41f4b71Sopenharmony_ci
3265e41f4b71Sopenharmony_ci| 类型                | 说明                                  |
3266e41f4b71Sopenharmony_ci| ------------------- | ------------------------------------- |
3267e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回自然对数运算后的Decimal对象实例。 |
3268e41f4b71Sopenharmony_ci
3269e41f4b71Sopenharmony_ci**错误码:**
3270e41f4b71Sopenharmony_ci
3271e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。
3272e41f4b71Sopenharmony_ci
3273e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
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**示例:**
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_ci返回一个值为以2为底n的对数的Decimal对象。
3290e41f4b71Sopenharmony_ci
3291e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
3292e41f4b71Sopenharmony_ci
3293e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
3294e41f4b71Sopenharmony_ci
3295e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
3296e41f4b71Sopenharmony_ci
3297e41f4b71Sopenharmony_ci**参数:**
3298e41f4b71Sopenharmony_ci
3299e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明             |
3300e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | ---------------- |
3301e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 对数运算的真数。 |
3302e41f4b71Sopenharmony_ci
3303e41f4b71Sopenharmony_ci**返回值:**
3304e41f4b71Sopenharmony_ci
3305e41f4b71Sopenharmony_ci| 类型                | 说明                                       |
3306e41f4b71Sopenharmony_ci| ------------------- | ------------------------------------------ |
3307e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回以2为底的对数运算后的Decimal对象实例。 |
3308e41f4b71Sopenharmony_ci
3309e41f4b71Sopenharmony_ci**错误码:**
3310e41f4b71Sopenharmony_ci
3311e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。
3312e41f4b71Sopenharmony_ci
3313e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
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**示例:**
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_ci返回一个值为以10为底n的对数的Decimal对象。
3330e41f4b71Sopenharmony_ci
3331e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
3332e41f4b71Sopenharmony_ci
3333e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
3334e41f4b71Sopenharmony_ci
3335e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
3336e41f4b71Sopenharmony_ci
3337e41f4b71Sopenharmony_ci**参数:**
3338e41f4b71Sopenharmony_ci
3339e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明             |
3340e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | ---------------- |
3341e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 对数运算的真数。 |
3342e41f4b71Sopenharmony_ci
3343e41f4b71Sopenharmony_ci**返回值:**
3344e41f4b71Sopenharmony_ci
3345e41f4b71Sopenharmony_ci| 类型                | 说明                                        |
3346e41f4b71Sopenharmony_ci| ------------------- | ------------------------------------------- |
3347e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回以10为底的对数运算后的Decimal对象实例。 |
3348e41f4b71Sopenharmony_ci
3349e41f4b71Sopenharmony_ci**错误码:**
3350e41f4b71Sopenharmony_ci
3351e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。
3352e41f4b71Sopenharmony_ci
3353e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
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**示例:**
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_ci返回一个新的Decimal,其值是n的余弦值。
3370e41f4b71Sopenharmony_ci
3371e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
3372e41f4b71Sopenharmony_ci
3373e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
3374e41f4b71Sopenharmony_ci
3375e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
3376e41f4b71Sopenharmony_ci
3377e41f4b71Sopenharmony_ci**参数:**
3378e41f4b71Sopenharmony_ci
3379e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明             |
3380e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | ---------------- |
3381e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 要求余弦值的值。 |
3382e41f4b71Sopenharmony_ci
3383e41f4b71Sopenharmony_ci**返回值:**
3384e41f4b71Sopenharmony_ci
3385e41f4b71Sopenharmony_ci| 类型                | 说明                                   |
3386e41f4b71Sopenharmony_ci| ------------------- | -------------------------------------- |
3387e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回n的余弦值对应的Decimal对象实例。 |
3388e41f4b71Sopenharmony_ci
3389e41f4b71Sopenharmony_ci**错误码:**
3390e41f4b71Sopenharmony_ci
3391e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3392e41f4b71Sopenharmony_ci
3393e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
3394e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
3395e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
3396e41f4b71Sopenharmony_ci
3397e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal,其值是n的正弦值。
3409e41f4b71Sopenharmony_ci
3410e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
3411e41f4b71Sopenharmony_ci
3412e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
3413e41f4b71Sopenharmony_ci
3414e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
3415e41f4b71Sopenharmony_ci
3416e41f4b71Sopenharmony_ci**参数:**
3417e41f4b71Sopenharmony_ci
3418e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明             |
3419e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | ---------------- |
3420e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 要求正弦值的值。 |
3421e41f4b71Sopenharmony_ci
3422e41f4b71Sopenharmony_ci**返回值:**
3423e41f4b71Sopenharmony_ci
3424e41f4b71Sopenharmony_ci| 类型                | 说明                                   |
3425e41f4b71Sopenharmony_ci| ------------------- | -------------------------------------- |
3426e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回n的正弦值对应的Decimal对象实例。 |
3427e41f4b71Sopenharmony_ci
3428e41f4b71Sopenharmony_ci**错误码:**
3429e41f4b71Sopenharmony_ci
3430e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3431e41f4b71Sopenharmony_ci
3432e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
3433e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
3434e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
3435e41f4b71Sopenharmony_ci
3436e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal,其值是n的正切值。
3448e41f4b71Sopenharmony_ci
3449e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
3450e41f4b71Sopenharmony_ci
3451e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
3452e41f4b71Sopenharmony_ci
3453e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
3454e41f4b71Sopenharmony_ci
3455e41f4b71Sopenharmony_ci**参数:**
3456e41f4b71Sopenharmony_ci
3457e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明             |
3458e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | ---------------- |
3459e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 要求正切值的值。 |
3460e41f4b71Sopenharmony_ci
3461e41f4b71Sopenharmony_ci**返回值:**
3462e41f4b71Sopenharmony_ci
3463e41f4b71Sopenharmony_ci| 类型                | 说明                                   |
3464e41f4b71Sopenharmony_ci| ------------------- | -------------------------------------- |
3465e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回n的正切值对应的Decimal对象实例。 |
3466e41f4b71Sopenharmony_ci
3467e41f4b71Sopenharmony_ci**错误码:**
3468e41f4b71Sopenharmony_ci
3469e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3470e41f4b71Sopenharmony_ci
3471e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
3472e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
3473e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
3474e41f4b71Sopenharmony_ci
3475e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal,其值是n的双曲余弦值。
3487e41f4b71Sopenharmony_ci
3488e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
3489e41f4b71Sopenharmony_ci
3490e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
3491e41f4b71Sopenharmony_ci
3492e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
3493e41f4b71Sopenharmony_ci
3494e41f4b71Sopenharmony_ci**参数:**
3495e41f4b71Sopenharmony_ci
3496e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明                   |
3497e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | ---------------------- |
3498e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 需要求双曲余弦值的值。 |
3499e41f4b71Sopenharmony_ci
3500e41f4b71Sopenharmony_ci**返回值:**
3501e41f4b71Sopenharmony_ci
3502e41f4b71Sopenharmony_ci| 类型                | 说明                                       |
3503e41f4b71Sopenharmony_ci| ------------------- | ------------------------------------------ |
3504e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回n的双曲余弦值对应的Decimal对象实例。 |
3505e41f4b71Sopenharmony_ci
3506e41f4b71Sopenharmony_ci**错误码:**
3507e41f4b71Sopenharmony_ci
3508e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3509e41f4b71Sopenharmony_ci
3510e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
3511e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
3512e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
3513e41f4b71Sopenharmony_ci
3514e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal,其值是n的双曲正弦值。
3526e41f4b71Sopenharmony_ci
3527e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
3528e41f4b71Sopenharmony_ci
3529e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
3530e41f4b71Sopenharmony_ci
3531e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
3532e41f4b71Sopenharmony_ci
3533e41f4b71Sopenharmony_ci**参数:**
3534e41f4b71Sopenharmony_ci
3535e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明                   |
3536e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | ---------------------- |
3537e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 需要求双曲正弦值的值。 |
3538e41f4b71Sopenharmony_ci
3539e41f4b71Sopenharmony_ci**返回值:**
3540e41f4b71Sopenharmony_ci
3541e41f4b71Sopenharmony_ci| 类型                | 说明                                       |
3542e41f4b71Sopenharmony_ci| ------------------- | ------------------------------------------ |
3543e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回n的双曲正弦值对应的Decimal对象实例。 |
3544e41f4b71Sopenharmony_ci
3545e41f4b71Sopenharmony_ci**错误码:**
3546e41f4b71Sopenharmony_ci
3547e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3548e41f4b71Sopenharmony_ci
3549e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
3550e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
3551e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
3552e41f4b71Sopenharmony_ci
3553e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal,其值是n的双曲正切值。
3565e41f4b71Sopenharmony_ci
3566e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
3567e41f4b71Sopenharmony_ci
3568e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
3569e41f4b71Sopenharmony_ci
3570e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
3571e41f4b71Sopenharmony_ci
3572e41f4b71Sopenharmony_ci**参数:**
3573e41f4b71Sopenharmony_ci
3574e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明                   |
3575e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | ---------------------- |
3576e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 需要求双曲正切值的值。 |
3577e41f4b71Sopenharmony_ci
3578e41f4b71Sopenharmony_ci**返回值:**
3579e41f4b71Sopenharmony_ci
3580e41f4b71Sopenharmony_ci| 类型                | 说明                                       |
3581e41f4b71Sopenharmony_ci| ------------------- | ------------------------------------------ |
3582e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回n的双曲正切值对应的Decimal对象实例。 |
3583e41f4b71Sopenharmony_ci
3584e41f4b71Sopenharmony_ci**错误码:**
3585e41f4b71Sopenharmony_ci
3586e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3587e41f4b71Sopenharmony_ci
3588e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
3589e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
3590e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
3591e41f4b71Sopenharmony_ci
3592e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal,其值是n的反余弦值。
3604e41f4b71Sopenharmony_ci
3605e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
3606e41f4b71Sopenharmony_ci
3607e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
3608e41f4b71Sopenharmony_ci
3609e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
3610e41f4b71Sopenharmony_ci
3611e41f4b71Sopenharmony_ci**参数:**
3612e41f4b71Sopenharmony_ci
3613e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明                 |
3614e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | -------------------- |
3615e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 需要求反余弦值的值。 |
3616e41f4b71Sopenharmony_ci
3617e41f4b71Sopenharmony_ci**返回值:**
3618e41f4b71Sopenharmony_ci
3619e41f4b71Sopenharmony_ci| 类型                | 说明                                   |
3620e41f4b71Sopenharmony_ci| ------------------- | -------------------------------------- |
3621e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回n的反余弦值对应的Decimal对象实例。 |
3622e41f4b71Sopenharmony_ci
3623e41f4b71Sopenharmony_ci**错误码**:
3624e41f4b71Sopenharmony_ci
3625e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。
3626e41f4b71Sopenharmony_ci
3627e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
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**示例:**
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_ci返回一个新的Decimal,其值是n的反正弦值。
3644e41f4b71Sopenharmony_ci
3645e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
3646e41f4b71Sopenharmony_ci
3647e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
3648e41f4b71Sopenharmony_ci
3649e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
3650e41f4b71Sopenharmony_ci
3651e41f4b71Sopenharmony_ci**参数:**
3652e41f4b71Sopenharmony_ci
3653e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明                 |
3654e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | -------------------- |
3655e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 需要求反正弦值的值。 |
3656e41f4b71Sopenharmony_ci
3657e41f4b71Sopenharmony_ci**返回值:**
3658e41f4b71Sopenharmony_ci
3659e41f4b71Sopenharmony_ci| 类型                | 说明                                   |
3660e41f4b71Sopenharmony_ci| ------------------- | -------------------------------------- |
3661e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回n的反正弦值对应的Decimal对象实例。 |
3662e41f4b71Sopenharmony_ci
3663e41f4b71Sopenharmony_ci**错误码**:
3664e41f4b71Sopenharmony_ci
3665e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。
3666e41f4b71Sopenharmony_ci
3667e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
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**示例:**
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_ci返回一个新的Decimal,其值是n的反正切值。
3684e41f4b71Sopenharmony_ci
3685e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
3686e41f4b71Sopenharmony_ci
3687e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
3688e41f4b71Sopenharmony_ci
3689e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
3690e41f4b71Sopenharmony_ci
3691e41f4b71Sopenharmony_ci**参数:**
3692e41f4b71Sopenharmony_ci
3693e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明                 |
3694e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | -------------------- |
3695e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 需要求反正切值的值。 |
3696e41f4b71Sopenharmony_ci
3697e41f4b71Sopenharmony_ci**返回值:**
3698e41f4b71Sopenharmony_ci
3699e41f4b71Sopenharmony_ci| 类型                | 说明                                   |
3700e41f4b71Sopenharmony_ci| ------------------- | -------------------------------------- |
3701e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回n的反正切值对应的Decimal对象实例。 |
3702e41f4b71Sopenharmony_ci
3703e41f4b71Sopenharmony_ci**错误码**:
3704e41f4b71Sopenharmony_ci
3705e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。
3706e41f4b71Sopenharmony_ci
3707e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
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**示例:**
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_ci返回一个新的Decimal,其值是n的双曲余弦值的倒数。
3724e41f4b71Sopenharmony_ci
3725e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
3726e41f4b71Sopenharmony_ci
3727e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
3728e41f4b71Sopenharmony_ci
3729e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
3730e41f4b71Sopenharmony_ci
3731e41f4b71Sopenharmony_ci**参数:**
3732e41f4b71Sopenharmony_ci
3733e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明                       |
3734e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | -------------------------- |
3735e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 需要求双曲余弦的倒数的值。 |
3736e41f4b71Sopenharmony_ci
3737e41f4b71Sopenharmony_ci**返回值:**
3738e41f4b71Sopenharmony_ci
3739e41f4b71Sopenharmony_ci| 类型                | 说明                                           |
3740e41f4b71Sopenharmony_ci| ------------------- | ---------------------------------------------- |
3741e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回n的双曲余弦的倒数对应的Decimal对象实例。 |
3742e41f4b71Sopenharmony_ci
3743e41f4b71Sopenharmony_ci**错误码**:
3744e41f4b71Sopenharmony_ci
3745e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。
3746e41f4b71Sopenharmony_ci
3747e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
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**示例:**
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_ci返回一个新的Decimal,其值是n的双曲正弦值的倒数。
3764e41f4b71Sopenharmony_ci
3765e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
3766e41f4b71Sopenharmony_ci
3767e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
3768e41f4b71Sopenharmony_ci
3769e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
3770e41f4b71Sopenharmony_ci
3771e41f4b71Sopenharmony_ci**参数:**
3772e41f4b71Sopenharmony_ci
3773e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明                       |
3774e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | -------------------------- |
3775e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 需要求双曲正弦的倒数的值。 |
3776e41f4b71Sopenharmony_ci
3777e41f4b71Sopenharmony_ci**返回值:**
3778e41f4b71Sopenharmony_ci
3779e41f4b71Sopenharmony_ci| 类型                | 说明                                           |
3780e41f4b71Sopenharmony_ci| ------------------- | ---------------------------------------------- |
3781e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回n的双曲正弦的倒数对应的Decimal对象实例。 |
3782e41f4b71Sopenharmony_ci
3783e41f4b71Sopenharmony_ci**错误码**:
3784e41f4b71Sopenharmony_ci
3785e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。
3786e41f4b71Sopenharmony_ci
3787e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
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**示例:**
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_ci返回一个新的Decimal,其值是n的双曲正切值的倒数。
3804e41f4b71Sopenharmony_ci
3805e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
3806e41f4b71Sopenharmony_ci
3807e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
3808e41f4b71Sopenharmony_ci
3809e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
3810e41f4b71Sopenharmony_ci
3811e41f4b71Sopenharmony_ci**参数:**
3812e41f4b71Sopenharmony_ci
3813e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明                       |
3814e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | -------------------------- |
3815e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 需要求双曲正切的倒数的值。 |
3816e41f4b71Sopenharmony_ci
3817e41f4b71Sopenharmony_ci**返回值:**
3818e41f4b71Sopenharmony_ci
3819e41f4b71Sopenharmony_ci| 类型                | 说明                                           |
3820e41f4b71Sopenharmony_ci| ------------------- | ---------------------------------------------- |
3821e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回n的双曲正切的倒数对应的Decimal对象实例。 |
3822e41f4b71Sopenharmony_ci
3823e41f4b71Sopenharmony_ci**错误码**:
3824e41f4b71Sopenharmony_ci
3825e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。
3826e41f4b71Sopenharmony_ci
3827e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
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**示例:**
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_ci返回一个新的Decimal,其值是为-π到π范围内的y/x反正切值。
3844e41f4b71Sopenharmony_ci
3845e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
3846e41f4b71Sopenharmony_ci
3847e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
3848e41f4b71Sopenharmony_ci
3849e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
3850e41f4b71Sopenharmony_ci
3851e41f4b71Sopenharmony_ci**参数:**
3852e41f4b71Sopenharmony_ci
3853e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明           |
3854e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | -------------- |
3855e41f4b71Sopenharmony_ci| y      | [Value](#value) | 是   | 除法的被除数。 |
3856e41f4b71Sopenharmony_ci| x      | [Value](#value) | 是   | 除法的除数。   |
3857e41f4b71Sopenharmony_ci
3858e41f4b71Sopenharmony_ci**返回值:**
3859e41f4b71Sopenharmony_ci
3860e41f4b71Sopenharmony_ci| 类型                | 说明                                                       |
3861e41f4b71Sopenharmony_ci| ------------------- | ---------------------------------------------------------- |
3862e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回-pi 到 pi 范围内的"y/x"反正切值对应的Decimal对象实例。 |
3863e41f4b71Sopenharmony_ci
3864e41f4b71Sopenharmony_ci**错误码**:
3865e41f4b71Sopenharmony_ci
3866e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。
3867e41f4b71Sopenharmony_ci
3868e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
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**示例:**
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_ci返回一个新的Decimal,其值为参数平方和的平方根。
3885e41f4b71Sopenharmony_ci
3886e41f4b71Sopenharmony_ci使用[DecimalConfig.precision](#decimalconfig)的值进行有效数字的保留,使用[DecimalConfig.rounding](#decimalconfig)的值设置舍入模式。
3887e41f4b71Sopenharmony_ci
3888e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
3889e41f4b71Sopenharmony_ci
3890e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
3891e41f4b71Sopenharmony_ci
3892e41f4b71Sopenharmony_ci**参数:**
3893e41f4b71Sopenharmony_ci
3894e41f4b71Sopenharmony_ci| 参数名 | 类型              | 必填 | 说明                 |
3895e41f4b71Sopenharmony_ci| ------ | ----------------- | ---- | -------------------- |
3896e41f4b71Sopenharmony_ci| n      | [Value](#value)[] | 是   | 需要求平方和的数组。 |
3897e41f4b71Sopenharmony_ci
3898e41f4b71Sopenharmony_ci**返回值:**
3899e41f4b71Sopenharmony_ci
3900e41f4b71Sopenharmony_ci| 类型                | 说明                                              |
3901e41f4b71Sopenharmony_ci| ------------------- | ------------------------------------------------- |
3902e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回值为所有参数平方和的平方根的Decimal对象实例。 |
3903e41f4b71Sopenharmony_ci
3904e41f4b71Sopenharmony_ci**错误码**:
3905e41f4b71Sopenharmony_ci
3906e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3907e41f4b71Sopenharmony_ci
3908e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
3909e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
3910e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
3911e41f4b71Sopenharmony_ci
3912e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个值为所有参数中最大值的Decimal对象。
3924e41f4b71Sopenharmony_ci
3925e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
3926e41f4b71Sopenharmony_ci
3927e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
3928e41f4b71Sopenharmony_ci
3929e41f4b71Sopenharmony_ci**参数:**
3930e41f4b71Sopenharmony_ci
3931e41f4b71Sopenharmony_ci| 参数名 | 类型              | 必填 | 说明                 |
3932e41f4b71Sopenharmony_ci| ------ | ----------------- | ---- | -------------------- |
3933e41f4b71Sopenharmony_ci| n      | [Value](#value)[] | 是   | 需要求最大值的数组。 |
3934e41f4b71Sopenharmony_ci
3935e41f4b71Sopenharmony_ci**返回值:**
3936e41f4b71Sopenharmony_ci
3937e41f4b71Sopenharmony_ci| 类型                | 说明                                      |
3938e41f4b71Sopenharmony_ci| ------------------- | ----------------------------------------- |
3939e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回所有参数中的最大值的Decimal对象实例。 |
3940e41f4b71Sopenharmony_ci
3941e41f4b71Sopenharmony_ci**错误码**:
3942e41f4b71Sopenharmony_ci
3943e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3944e41f4b71Sopenharmony_ci
3945e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
3946e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
3947e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
3948e41f4b71Sopenharmony_ci
3949e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个值为所有参数中最小值的Decimal对象。
3961e41f4b71Sopenharmony_ci
3962e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
3963e41f4b71Sopenharmony_ci
3964e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
3965e41f4b71Sopenharmony_ci
3966e41f4b71Sopenharmony_ci**参数:**
3967e41f4b71Sopenharmony_ci
3968e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明                 |
3969e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | -------------------- |
3970e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 需要求最小值的数组。 |
3971e41f4b71Sopenharmony_ci
3972e41f4b71Sopenharmony_ci**返回值:**
3973e41f4b71Sopenharmony_ci
3974e41f4b71Sopenharmony_ci| 类型                | 说明                                      |
3975e41f4b71Sopenharmony_ci| ------------------- | ----------------------------------------- |
3976e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回所有参数中的最小值的Decimal对象实例。 |
3977e41f4b71Sopenharmony_ci
3978e41f4b71Sopenharmony_ci**错误码**:
3979e41f4b71Sopenharmony_ci
3980e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
3981e41f4b71Sopenharmony_ci
3982e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
3983e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
3984e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
3985e41f4b71Sopenharmony_ci
3986e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个值为大于等于0小于1的随机值的Decimal对象。
3998e41f4b71Sopenharmony_ci
3999e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
4000e41f4b71Sopenharmony_ci
4001e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
4002e41f4b71Sopenharmony_ci
4003e41f4b71Sopenharmony_ci**返回值:**
4004e41f4b71Sopenharmony_ci
4005e41f4b71Sopenharmony_ci| 类型                | 说明                                      |
4006e41f4b71Sopenharmony_ci| ------------------- | ----------------------------------------- |
4007e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 大于等于0小于1的随机值的Decimal对象实例。 |
4008e41f4b71Sopenharmony_ci
4009e41f4b71Sopenharmony_ci**错误码:**
4010e41f4b71Sopenharmony_ci
4011e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。
4012e41f4b71Sopenharmony_ci
4013e41f4b71Sopenharmony_ci| 错误码ID | 错误信息            |
4014e41f4b71Sopenharmony_ci| -------- | ------------------- |
4015e41f4b71Sopenharmony_ci| 10200061 | Crypto unavailable. |
4016e41f4b71Sopenharmony_ci
4017e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个值为大于等于0小于1的随机值的Decimal对象,随机值保留significantDigits位有效数字。
4028e41f4b71Sopenharmony_ci
4029e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
4030e41f4b71Sopenharmony_ci
4031e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
4032e41f4b71Sopenharmony_ci
4033e41f4b71Sopenharmony_ci**参数:**
4034e41f4b71Sopenharmony_ci
4035e41f4b71Sopenharmony_ci| 参数名            | 类型   | 必填 | 说明                   |
4036e41f4b71Sopenharmony_ci| ----------------- | ------ | ---- | ---------------------- |
4037e41f4b71Sopenharmony_ci| significantDigits | number | 是   | 随机值保留的有效数字。 |
4038e41f4b71Sopenharmony_ci
4039e41f4b71Sopenharmony_ci**返回值:**
4040e41f4b71Sopenharmony_ci
4041e41f4b71Sopenharmony_ci| 类型                | 说明                                      |
4042e41f4b71Sopenharmony_ci| ------------------- | ----------------------------------------- |
4043e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 大于等于0小于1的随机值的Decimal对象实例。 |
4044e41f4b71Sopenharmony_ci
4045e41f4b71Sopenharmony_ci**错误码:**
4046e41f4b71Sopenharmony_ci
4047e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。
4048e41f4b71Sopenharmony_ci
4049e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
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**示例:**
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_ci根据参数的值进行判断返回对应的值:当n>0返回1,当n<0返回-1,当n==0返回0,当n==-0返回-0,否则返回NaN。
4065e41f4b71Sopenharmony_ci
4066e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
4067e41f4b71Sopenharmony_ci
4068e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
4069e41f4b71Sopenharmony_ci
4070e41f4b71Sopenharmony_ci**参数:**
4071e41f4b71Sopenharmony_ci
4072e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明           |
4073e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | -------------- |
4074e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 需要判断的值。 |
4075e41f4b71Sopenharmony_ci
4076e41f4b71Sopenharmony_ci**返回值:**
4077e41f4b71Sopenharmony_ci
4078e41f4b71Sopenharmony_ci| 类型   | 说明                               |
4079e41f4b71Sopenharmony_ci| ------ | ---------------------------------- |
4080e41f4b71Sopenharmony_ci| number | 根据参数的值进行判断返回对应的值。 |
4081e41f4b71Sopenharmony_ci
4082e41f4b71Sopenharmony_ci**错误码:**
4083e41f4b71Sopenharmony_ci
4084e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
4085e41f4b71Sopenharmony_ci
4086e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
4087e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
4088e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
4089e41f4b71Sopenharmony_ci
4090e41f4b71Sopenharmony_ci**示例:**
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_ci返回一个新的Decimal,其值是使用[DecimalConfig.rounding](#decimalconfig)模式舍入为整数的n。
4102e41f4b71Sopenharmony_ci
4103e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
4104e41f4b71Sopenharmony_ci
4105e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
4106e41f4b71Sopenharmony_ci
4107e41f4b71Sopenharmony_ci**参数:**
4108e41f4b71Sopenharmony_ci
4109e41f4b71Sopenharmony_ci| 参数名 | 类型            | 必填 | 说明           |
4110e41f4b71Sopenharmony_ci| ------ | --------------- | ---- | -------------- |
4111e41f4b71Sopenharmony_ci| n      | [Value](#value) | 是   | 需要舍入的值。 |
4112e41f4b71Sopenharmony_ci
4113e41f4b71Sopenharmony_ci**返回值:**
4114e41f4b71Sopenharmony_ci
4115e41f4b71Sopenharmony_ci| 类型                | 说明                                      |
4116e41f4b71Sopenharmony_ci| ------------------- | ----------------------------------------- |
4117e41f4b71Sopenharmony_ci| [Decimal](#decimal) | 返回舍入之后的整数对应的Decimal对象实例。 |
4118e41f4b71Sopenharmony_ci
4119e41f4b71Sopenharmony_ci**错误码:**
4120e41f4b71Sopenharmony_ci
4121e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)。
4122e41f4b71Sopenharmony_ci
4123e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
4124e41f4b71Sopenharmony_ci| -------- | ------------------------------------------------------------ |
4125e41f4b71Sopenharmony_ci| 401      | Parameter error. Possible causes:<br/>1. Incorrect parameter types;<br/>2. Parameter verification failed. |
4126e41f4b71Sopenharmony_ci
4127e41f4b71Sopenharmony_ci**示例:**
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_ci用于设置Decimal的配置属性。
4140e41f4b71Sopenharmony_ci
4141e41f4b71Sopenharmony_ci**原子化服务API**:从API version 12 开始,该接口支持在原子化服务中使用。
4142e41f4b71Sopenharmony_ci
4143e41f4b71Sopenharmony_ci**系统能力**:SystemCapability.Utils.Lang
4144e41f4b71Sopenharmony_ci
4145e41f4b71Sopenharmony_ci**参数:**
4146e41f4b71Sopenharmony_ci
4147e41f4b71Sopenharmony_ci| 参数名 | 类型                            | 必填 | 说明                 |
4148e41f4b71Sopenharmony_ci| ------ | ------------------------------- | ---- | -------------------- |
4149e41f4b71Sopenharmony_ci| object | [DecimalConfig](#decimalconfig) | 是   | 需要配置的属性集合。 |
4150e41f4b71Sopenharmony_ci
4151e41f4b71Sopenharmony_ci**错误码:**
4152e41f4b71Sopenharmony_ci
4153e41f4b71Sopenharmony_ci以下错误码的详细介绍请参见[通用错误码](../errorcode-universal.md)和[语言基础类库错误码](errorcode-utils.md)。
4154e41f4b71Sopenharmony_ci
4155e41f4b71Sopenharmony_ci| 错误码ID | 错误信息                                                     |
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**示例:**
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// 将配置属性全部设置为默认值
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// 最大有效位数设置为10,其余配置属性设置为默认值
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// toExpNeg和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// 所有数据均使用科学计数法表示
4196e41f4b71Sopenharmony_ciDecimal.set({ toExpPos: 0 })
4197e41f4b71Sopenharmony_ci
4198e41f4b71Sopenharmony_ci// minE和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```