views:

339

answers:

3

Is there any way to set a default value to a field in a report? I have a lot of String fields in a report and would like them to display "0,00" when they're null.

A: 

Did you try set a pattern in the text field?

If you are using iReport this can be found in the properties for the text field in the Text Field Properties section.

Try something along the lines of ###0.00 to represent 1234.56, which would always display 0.00 even if it is null.

Gordon
A: 

Supposing the field name is "value", in the "Text Field Expression", write:

($F{value} != null) ? $F{value} : "0.00"

medopal
+1  A: 

medopal's answer is good, but 2 additions:

1) You can make the syntax shorter:

($F{field_name}) ? $F{field_name} : "0.00"

2) Make sure your "else" data is of the same class as the field's value, otherwise you'll get errors when it tries to coerce numbers into string, etc. etc. This was something that, as I started out, I mixed up.

semperos