One Star

[resolved] Big Data - BigDecimal math operation (division)

Hi,
I am trying to divide a bigdecimal number with an integer. I tried to convert the integer (denominator) to bigdecimal and double and ran into issues. What is the right approach in doing math operations between a bigdecimal (numerator) and an integer or long (denominator).
For example: in my tMap I tried the following and getting error for all.
I want to do the following arithmetic: amount/nodays (where amount = BigDecimal type, Var.nodays = integer type)
(row1.amount).divide(new BigDecimal(Integer.toString(Var.nodays))) 
Error: Rounding mode cannot be resolved to a variable
(row1.campaign_budget).divide(Double.valueOf(Var.nodays)) 
Error: Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
RoundingMode cannot be resolved to a variable
The method divide(BigDecimal) in the type BigDecimal is not applicable for the arguments (Double)
at 
(row1.amount).divide(new BigDecimal(Integer.toString(Var.nodays)), 10, RoundingMode.CEILING) 
Error:
Exception in thread "main" java.lang.Error: Unresolved compilation problems: 
RoundingMode cannot be resolved to a variable
1 ACCEPTED SOLUTION

Accepted Solutions
One Star

Re: [resolved] Big Data - BigDecimal math operation (division)

Figured out the solution.
(row1.amount).divide(new BigDecimal(Var.nodays), java.math.RoundingMode.HALF_UP) 
Solution reference: couldn't post URL as I do not meet the minimum posting requirements.
Kudos tolijolawrance posted solution on 2011-05-13 11:24:06 Viewtopic id# 15684
Now it works!
2 REPLIES
One Star

Re: [resolved] Big Data - BigDecimal math operation (division)

Anyone? Would highly appreciate help with the BigDecimal math (division) issue.
Thanks,
ShaunK
One Star

Re: [resolved] Big Data - BigDecimal math operation (division)

Figured out the solution.
(row1.amount).divide(new BigDecimal(Var.nodays), java.math.RoundingMode.HALF_UP) 
Solution reference: couldn't post URL as I do not meet the minimum posting requirements.
Kudos tolijolawrance posted solution on 2011-05-13 11:24:06 Viewtopic id# 15684
Now it works!