Do not input private or sensitive data. View Qlik Privacy & Cookie Policy.
Skip to main content

Announcements
Join us to spark ideas for how to put the latest capabilities into action. Register here!
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

[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
Labels (3)
1 Solution

Accepted Solutions
Anonymous
Not applicable
Author

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!

View solution in original post

2 Replies
Anonymous
Not applicable
Author

Anyone? Would highly appreciate help with the BigDecimal math (division) issue.
Thanks,
ShaunK
Anonymous
Not applicable
Author

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!