expression and division

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
tadan's picture
-1
Joined: Oct 10 2007 - 1:03am
Last seen: 15 years 8 months ago

4 Answers:

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.
jmurray's picture
6389
Joined: Dec 11 2006 - 11:19am
Last seen: 16 years 5 months ago
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
tadan's picture
-1
Joined: Oct 10 2007 - 1:03am
Last seen: 15 years 8 months ago
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
jmurray's picture
6389
Joined: Dec 11 2006 - 11:19am
Last seen: 16 years 5 months ago
Dear jmurray,
matny thanks for you're support I've resolved 100%!
Many thanks again.

All the best :-)

Francesco
tadan's picture
-1
Joined: Oct 10 2007 - 1:03am
Last seen: 15 years 8 months ago
Feedback
randomness