Dividing double returning null value

Based upon other questions that seem similar, I have tried the following formula. I am getting null.  This should be as simple as 3.00/2 and display 1.50 however it is not working it still shows null.  I have confirmed that the fields contain values for all fields. The Price Qty field is an integer and the Price field is BigDecimal, but this sets the values to double for the purposes of this variable correct?  Anyone know what I am missing?

new Double($V{UnitPrice}.doubleValue() == 0 ? 0 : ($F{Price Qty}.doubleValue()/$F{Price}.doubleValue()))

amartin_2's picture
Joined: Mar 4 2015 - 5:18am
Last seen: 8 years 2 months ago

1 Answer:

As you are referencing a Variable, I would say that $V{UnitPrice} is NULL, and therefore your final result is also NULL

nuno-miguel-lourenco's picture
Joined: Feb 23 2015 - 10:21am
Last seen: 7 years 9 months ago

I removed the "new Double($V{UnitPrice}.doubleValue() == 0 ? 0 : " portion from the above code and it calculates correctly now!!! Thanks for the help! It is giving me.5 I would like to see two decimal places, do you know how to do that?

amartin_2 - 8 years 2 months ago

You just need to something like the following:
new java.text.DecimalFormat("#0.00").format(<put your expression here>)

nuno-miguel-lourenco - 8 years 2 months ago