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

Announcements
Qlik Open Lakehouse is Now Generally Available! Discover the key highlights and partner resources here.
cancel
Showing results for 
Search instead for 
Did you mean: 
jensej
Creator
Creator

How to calculate this correct

Hello there
So i have a problem.
In my mssql salestable i have 3 columns.
BuyinPrice (Bigdecimal)
SalesPrice (Bigdecimal)
Amount (float)

I need to make this calculation to see how much i earn on each sale. And write that into my target db in a INT column.
SalesPrice*Amount-BuyinPrice*Amount = WINNING (int)

I made mistakes before when i calculated that rounded things up so i got the wrong value in the end.
Can someone help me with the code i have to use in tmap in my variable that counts this.

Is this Correct?
(row11.SalesPrice.multiply(BigDecimal.valueOf(row11.Amount))).subtract(row11.BuyinPrice.multiply(BigDecimal.valueOf(row11.Amount)))  

and then (int)Var.fromabove.doubleValue()  

Labels (2)
1 Reply
Anonymous
Not applicable

Hi 
Try this:
(row1. SalesPrice .multiply(new java.math.BigDecimal(row1. Amount .toString()) )).subtract(row1. BuyinPrice .multiply(new java.math.BigDecimal(row1. Amount .toString()) )) 

What are your expected result after converting the calculation result to an int value? For example, assuming the above calculation result is 14.99999 with BigDecimal type, what value do you expect to have for int type. 
14
or 
15 with rounding.