1

I have made a variable in Jasper Reports with a Value Class Name of java.math.BigDecimal. I set the expression as:

new BigDecimal(PRODUCT($F{CurrentValue},100)).divide($V{current_val_total})

but I keep getting the error:

The constructor BigDecimal(Number) is undefined 

and

net.sf.jasperreports.engine.JRException: Errors were encountered when compiling report expressions class file:
1. The constructor BigDecimal(Number) is undefined
            value = new BigDecimal(PRODUCT (((java.math.BigDecimal)field_CurrentValue.getValue()),100)).divide(((java.math.BigDecimal)variable_current_val_total.getValue())); //$JR_EXPR_ID=18$
                    <--------------------------------------------------------------------------------->
2. The constructor BigDecimal(Number) is undefined
            value = new BigDecimal(PRODUCT (((java.math.BigDecimal)field_CurrentValue.getOldValue()),100)).divide(((java.math.BigDecimal)variable_current_val_total.getOldValue())); //$JR_EXPR_ID=18$
                    <------------------------------------------------------------------------------------>
3. The constructor BigDecimal(Number) is undefined
            value = new BigDecimal(PRODUCT (((java.math.BigDecimal)field_CurrentValue.getValue()),100)).divide(((java.math.BigDecimal)variable_current_val_total.getEstimatedValue())); //$JR_EXPR_ID=18$
                    <--------------------------------------------------------------------------------->
3 errors
.
at   net.sf.jasperreports.engine.design.JRAbstractCompiler.compileReport(JRAbstractCompiler.java:215)
at net.sf.jasperreports.eclipse.builder.JasperReportCompiler.compileReport(JasperReportCompiler.java:195)
at com.jaspersoft.studio.editor.preview.view.control.ReportControler.compileJasperDesign(ReportControler.java:439)
at com.jaspersoft.studio.editor.preview.view.control.ReportControler.access$15(ReportControler.java:416)
at com.jaspersoft.studio.editor.preview.view.control.ReportControler$5.run(ReportControler.java:341)
at org.eclipse.core.internal.jobs.Worker.run(Worker.java:54)

How can I solve this?

Petter Friberg
  • 21,252
  • 9
  • 60
  • 109
Jickery
  • 237
  • 4
  • 15

1 Answers1

3

PRODUCT returns a java.lang.Number see Jasper Reports Functions.

There is no constructor in java.math.BigDecimal that takes java.lang.Number.

You need to use one of the constructors available in api, I would suggest BigDecimal(double val), hence calling the doubleValue() function on java.lang.Number

new BigDecimal(PRODUCT($F{CurrentValue},100).doubleValue()).divide($V{current_val_total})

or to use the String value of Number

new BigDecimal(PRODUCT($F{CurrentValue},100).toString()).divide($V{current_val_total})

Which one is "best" to use depends on the actual class of Number, see Convert Java Number to BigDecimal : best way for more information. However in report generation with normal rounding it will not make much difference.

Community
  • 1
  • 1
Petter Friberg
  • 21,252
  • 9
  • 60
  • 109