0

I am working on a MySql backed Jasper report. I have 5 BigDecimal Variables in my report. This report calculates the yearly charge of multiple services .I need to add the first 4 and the subtract the last one. Some of these these variables can potentially house fairly large values ( 8 figures ). I donot know how to do calculations is BigDecimal. I have tried making a Double variable and doing the following

Double.valueOf($V{enc}.doubleValue() + $V{Bed}.doubleValue()+$V{Diet}.doubleValue() + $V{Investigation}.doubleValue() - $V{ref}.doubleValue()) 

The report does not give any error but leads to 7.269307848E9 as shown below:

254350, 14589,  8122, 3708, 0   7.269307848E9 

( these are the values of the original variables except the last one which is the result of the calculation )

While searching for the solution, I did come across the following: ($V{enc}.ADD($V{Bed})).toString()

I am not sure how I can apply it in my case. This can add only two values.

I need to have a whole value, not decimal like above. By the way, I use iReport 1.2.0, which is a requirement for generating the report.

Alex K
  • 22,315
  • 19
  • 108
  • 236
  • `I need to have a whole value, not decimal like above` - What do you mean? – Alex K Sep 20 '20 at 18:51
  • I meant that it is displayed in the format 7.269307848E9( 7.269307848 *10^9) in double format . I wish to have the answer something like 726930784889 I posted this question and went to sleep. That is why the delay in answering. – Srikanth Kamath Sep 21 '20 at 08:17
  • Duplicates: [Format a BigDecimal as String with max 2 decimal digits, removing 0 on decimal part](https://stackoverflow.com/q/10269045/876298) & [Java format BigDecimal numbers with comma and 2 decimal place](https://stackoverflow.com/q/26101918/876298) – Alex K Sep 21 '20 at 16:13

0 Answers0