Getting null when dividing variable by field bigdecimal

Jaspersoft Community 'Read-Only' as of July 8, 2022

Transition to New TIBCO Community Just Weeks Away

You can still search, review wiki content, and review discussions in read-only mode. Please email with questions or issues requiring TIBCO review or response.

I am trying to make Jaspersoft Studio calculate a Markdown for the contents of the report.  Basically, I need to first divide the price by the price qty (2 for $3.00 would give me $1.50 unit price).  I then do the same thing for the regular retail (1 for $2.00 would give me a $2.00 unit price).  I then would subtract the regular unit price from the discounted unit price to get my markdown ($0.50).

I am using MySql.  Both active  price and regular price are set as Decimal and the price qty is set to integer.

First I create two variables and use the following expressions to convert the integer values to BigDecimal.  This seems to work fine, when I drag the variable into the report it shows the same value as the corrosponding field.  So far so good.

$V{Active Unit}.valueOf( $F{Price Qty} )

$V{Reg Unit}.valueOf( $F{Reg Retail Unit} )

The next two variables I create then divide a field by that variable. (I am at this point finding unit price 2 for $1.00 show as .50 this way). These are returning null.

$F{Price}.divide($V{Current Unit Price})

$F{Reg Retail}.divide($V{Regular Unit Price})

I then subtract the two newly created variables from each other (This is to find out my markdown for discounted items .75 - .50 is a .25 markdown per item). This is also returning null, although I don't know if this is because of the previous null or if it is its own problem.

$F{Reg Retail}.divide($V{Regular Unit Price})

Any ideas what I am doing wrong? I know very little java, I am using this through Jaspersoft Studio. Based on what I have read, I believe I have constrcuted this correctly. Anyone have any ideas?

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

Based upon other questions that seem similar, I have tried the following formula.  This time I am using the fields directly instead of a variable.  I am still 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.

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

amartin_2 - 7 years 4 months ago

0 Answers:

No answers yet