按整数划分bigdecimal [英] division of bigdecimal by integer

查看:223
本文介绍了按整数划分bigdecimal的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想将一个bigdecimal值除以一个整数。我已经舍入了bigdecimal值(如果它是133.333,那么舍入值是133)。下面是我的代码片段。

I want to divide a bigdecimal value with an integer.i have rounded the bigdecimal value(if it is 133.333 then rounded value is 133).given below is my code snippet.

v1 = v1.setScale(0, RoundingMode.HALF_UP);
int temp = BigDecimal.valueOf(v1.longValue()).divide(constant1);

常量的值是12.它显示错误消息

value of constant is 12. It is showing an error message that


BigDecimal类型中的方法除(BigDecimal)不适用于参数(int)

The method divide(BigDecimal) in the type BigDecimal is not applicable for the arguments (int)

任何人都可以帮我分区吗?

Can anyone help me to do the division?

推荐答案

更改

.divide(constant1);

.divide(new BigDecimal(constant1));






顺便说一下,你为什么不做点什么?喜欢


Btw, why don't you just do something like

int temp = (int) (Math.round(v1.doubleValue()) / constant1);

??

这篇关于按整数划分bigdecimal的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆