Jump to content
We've recently updated our Privacy Statement, available here ×

How to sum double datatype when the column contains null value


chakravarthy.9866

Recommended Posts

Hi All,

My report looks like below

Apr,May,Jun    ,July ,Total

null,null,120.00,null , null

I have created the variable for Sum and in Expression I have mentioned as $F{Apr}+$F{May}+$F{Jun}+$F{Jul}, in Total I am getting null value.

I can understand that if we have null values in other column result will be null, how to validate the double type with null and how to calculate the total?

 

Regards,

Chakravarthy

Link to comment
Share on other sites

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

Simplest way would be to  replace these null values as zero in your SQL with nvl function (if you are using oracle).

But this can also be done using Java.

  1. First you need to create variables for each month Apr, May, Jun, July, Total. 
  2. Inside these month variables check if the value is null and replace with Zero.Ex: $F{APR}!=null ? BigDecimal.valueOf($F{APR}) : BigDecimal.ZERO
  3. Then Add all these month variables inside the Total variable using .add method Ex: $V{APR}.add($V{MAY}).add($V{JUN}).add($V{JULY})
Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...