Philip Morris
Philip Morris

Reputation: 469

How to convert a BigDecimal to a Double using the query in Jasper Reports

I am having troubles converting BigDecimal (4 decimal places) to a Double (2 decimal places) in JasperReports. I tried CONVERT() and it was erroneous. Can someone enlighten me?

Upvotes: 0

Views: 3448

Answers (1)

Robert Mugattarov
Robert Mugattarov

Reputation: 1298

I am not sure what you mean by conversion. If you mean typecasting, then simply call BigDecimal.doubleValue()

But I assume you mean the display format - for that you may use the Pattern property of the report field. If you are using iReport then you can select a number format pattern from a number of format presets.

If your needs go beyond that functionality then you can create a custom decimal formatter. Here is what you can do:

  1. Create a report variable of type java.text.DecimalFormat
  2. Specify new java.text.DecimalFormat(your custom pattern here) as its initial value
  3. Call $V{formatter_variable_name}.format(Number) to get a formatted string

Upvotes: 2

Related Questions