hi all
I'm newbie of iReport, and I would like to take a field of my db (is an integer value), divided this by 100 and post the result in my report.
Could anyone help me please?
Many Thanks
Francesco
I'm newbie of iReport, and I would like to take a field of my db (is an integer value), divided this by 100 and post the result in my report.
Could anyone help me please?
Many Thanks
Francesco
4 Answers:
Posted on October 11, 2007 at 2:59am
1) You can do it in your source query:
SELECT FIELDNAME/100 as FIELDNAME
FROM SOMEWHERE
and set you TextField Expression to be simply $F{FIELDNAME}.
or
2) you can do it your report TextField by setting the TextField Expression to something like new java.lang.Double($F{FIELDNAME}.doubleValue()/100)
Either way you will need the TextField to be defined as a java.lang.Double or java.math.BigDecimal, depending on the size of your data.
You can set the output format using a variation on the "#,##0.00" format string. For example, "#,##0" will display integer values.
Have fun.
SELECT FIELDNAME/100 as FIELDNAME
FROM SOMEWHERE
and set you TextField Expression to be simply $F{FIELDNAME}.
or
2) you can do it your report TextField by setting the TextField Expression to something like new java.lang.Double($F{FIELDNAME}.doubleValue()/100)
Either way you will need the TextField to be defined as a java.lang.Double or java.math.BigDecimal, depending on the size of your data.
You can set the output format using a variation on the "#,##0.00" format string. For example, "#,##0" will display integer values.
Have fun.
Posted on October 11, 2007 at 1:59pm
Hi
many thanks for you're response.
If I try to follow the 2nd way, when I compile the report appairs an error that says:
"the method DoubleValue() is undefined for the type Integer".
I think this is referred to my field that is an integer but I'm not sure ... could you give me more help?
Many thanks
all the best
Francesco
many thanks for you're response.
If I try to follow the 2nd way, when I compile the report appairs an error that says:
"the method DoubleValue() is undefined for the type Integer".
I think this is referred to my field that is an integer but I'm not sure ... could you give me more help?
Many thanks
all the best
Francesco
Posted on October 11, 2007 at 10:40pm
You problem is that java is case sensitive: use doubleValue() not DoubleValue().
If your field is an Integer then you can always grab its intValue(), like this:
new java.lang.Double($F{FIELDNAME}.intValue()/100)
You TextField is still a java.lang.Double. You can force it to be a java.lang.Integer if you want, just recast the result like this:
new java.lang.Integer(new java.lang.Double($F{FIELDNAME}.intValue()/100).intValue())
.
Post edited by: jmurray, at: 2007/10/11 22:43
If your field is an Integer then you can always grab its intValue(), like this:
new java.lang.Double($F{FIELDNAME}.intValue()/100)
You TextField is still a java.lang.Double. You can force it to be a java.lang.Integer if you want, just recast the result like this:
new java.lang.Integer(new java.lang.Double($F{FIELDNAME}.intValue()/100).intValue())
.
Post edited by: jmurray, at: 2007/10/11 22:43