温馨提示×

Java中bigdecimal转integer怎么实现

小亿
158
2024-01-23 18:03:28
栏目: 编程语言

在Java中,可以使用BigDecimal类的intValue()方法将BigDecimal类型转换为Integer类型。例如:

BigDecimal decimal = new BigDecimal("10.5");
Integer integer = decimal.intValue();

在上述代码中,decimal是一个BigDecimal对象,表示一个带有小数的数值。然后,使用intValue()方法将decimal转换为Integer类型的整数。最终,变量integer将保存整数值10。

0