Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

division of bigdecimal by integer

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);

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

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

Can anyone help me to do the division?

like image 547
andro-girl Avatar asked Oct 19 '11 09:10

andro-girl


1 Answers

Change

.divide(constant1);

to

.divide(new BigDecimal(constant1));

Btw, why don't you just do something like

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

??

like image 151
aioobe Avatar answered Sep 21 '22 06:09

aioobe