怎么将BigDecimal转换成Int

时间:2024-10-27 04:17:45

1、将BigDecimal转换成Int:

BigDecimala=newBigDecimal(12.88)稆糨孝汶;

intb=a.intValue();

System.out.println(b);//b=12;

2、C#中将decimal转int

try{

intnumber=Decimal.ToInt32(xxx);

}

catch(OverflowExceptione)

{

//decimal值超出int值范围

}

怎么将BigDecimal转换成Int

扩展资料

使用BigDecimal类来进行计算:

1、用float或者double变量构建BigDecimal对象。

2、通过调用BigDecimal的加,减,乘,除等相应的方法进行算术运算。

3、把BigDecimal对象转换成float,double,int等类型。可以使用BigDecimal的构造方法或者静态方法的valueOf()方法把基本类型的变量构建成BigDecimal对象。

© 手抄报圈