Search code examples
javanulldoubledivide

Why is dividing double values returning null?


In Jaspersoft Studio I have tried the following expression. I am getting null but I don't understand why. 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 expression I am using is as follows:

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

Solution

  • Since you are using Double for your arithmetic, why not use the compareTo(Double anotherDouble)?

    Not sure if this is the source of your trouble, but it could be the == behaving in a way that you did not intend it to and returning false hence, the zero...