0

I am trying to build a report with multiple columns. I have a column total that represents the summation of the previous columns.

However, the value I am getting is of type BigDecimal and the return type of the .add method is BigDecimal and not integer, for example: 12.00 and I want it to be shown as only 12 in the report.

Here is my code:

TextColumnBuilder<Integer> col1 = col.column("Locked Users" , "Locked" , DataTypes.integerType());
TextColumnBuilder<Integer> col2 = col.column("Unlocked Users" , "unlocked" , DataTypes.integerType());
TextColumnBuilder<Integer> col3 = col.column("Failed Logins" , "invalid" , DataTypes.integerType());
TextColumnBuilder<Integer> col4 = col.column("Forgot Password" , "Passforget" , DataTypes.integerType());
TextColumnBuilder<BigDecimal> col5 = col1.add(col2).add(col3).add(col4).setTitle("Total");

How can I do it?

TT.
  • 15,774
  • 6
  • 47
  • 88
Abdalla Ismail
  • 409
  • 1
  • 4
  • 21
  • 1
    You can get the `int` value from a `BigDecimal` as follows, for example: `BigDecimal b = new BigDecimal("12.00")` then get the int value with `b.intValue()` – Omoro Nov 23 '16 at 13:37
  • thats in normal java , it doesnt apply on columns in dynamic reports – Abdalla Ismail Nov 23 '16 at 13:41
  • I don't know dynamic-reports but you could use BigInteger instead of BigDecimal. Something like this should give you format option I guess ... – AxelH Nov 23 '16 at 13:47
  • Then I am afraid you may have to do some `AbstractSimpleExpression` overriding using own inner classes. – Omoro Nov 23 '16 at 13:54

2 Answers2

2

By default Big Decimal type has following format "#,##0.00#"

You could override it for your column

 col5.setPattern("#,##0");
D.Shev
  • 341
  • 3
  • 7
1

if you don't want to use fraction then use the BigInteger instead of BigDecimal. Or you can use as below,

DecimalFormat df = new DecimalFormat("##"); 
df.format(yourNumber);
Zia
  • 1,001
  • 1
  • 13
  • 25