mnfaria1994 Posted August 3, 2015 Share Posted August 3, 2015 Hi. I have fields like200.00010.0005.000they are in a string. I want to sum them that and print it in the right format, 215.000 in this case. I tried creating a variable with the expression Double.parseDouble ($F{field20}) but it didn't work Link to comment Share on other sites More sharing options...
grafro Posted August 3, 2015 Share Posted August 3, 2015 You should define your field as Integer or Double and not as String, if it is a number! after that, its easy define a new variable with calculation operation sum, increment type none and reset type report.i think the expression should be your field ( $F{XYZ} ), the initial value expression should be 0value class name should be java.lang.Float or java.lang.Integer, depends on your data if your field will stay a String try the expression $F{XYZ}.replace(".", "") Link to comment Share on other sites More sharing options...
Solution hozawa Posted August 3, 2015 Solution Share Posted August 3, 2015 Seems to be working. <?xml version="1.0" encoding="UTF-8"?><!-- Created with Jaspersoft Studio version 6.1.0.final using JasperReports Library version 6.1.0 --><!-- 2015-08-04T05:40:04 --><jasperReportxmlns="http://jasperreports.sourceforge.net/jasperreports"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://jasperreports.sourceforge.net/jasperreportshttp://jasperreports.sourceforge.net/xsd/jasperreport.xsd" name="test"pageWidth="595" pageHeight="842" columnWidth="555" leftMargin="20"rightMargin="20" topMargin="20" bottomMargin="20"uuid="03c6ea1c-5c81-4a19-8d94-111f20cd415b"> <property name="com.jaspersoft.studio.data.defaultdataadapter" value="sampleDatabase"/> <queryString> <![CDATA[select * from test.test]]> </queryString> <field name="col1" class="java.lang.String"> <fieldDescription><![CDATA[]]></fieldDescription> </field> <field name="col2" class="java.lang.String"> <fieldDescription><![CDATA[]]></fieldDescription> </field> <field name="col3" class="java.lang.String"> <fieldDescription><![CDATA[]]></fieldDescription> </field> <variable name="Variable_1" class="java.lang.Double"> <initialValueExpression><![CDATA[Double.parseDouble ($F{col1})]]></initialValueExpression> </variable> <variable name="Variable_2" class="java.lang.Double"> <initialValueExpression><![CDATA[Double.parseDouble ($F{col2})]]></initialValueExpression> </variable> <variable name="Variable_3" class="java.lang.Double"> <initialValueExpression><![CDATA[Double.parseDouble ($F{col3})]]></initialValueExpression> </variable> <variable name="total" class="java.lang.Double"> <initialValueExpression><![CDATA[$V{Variable_1} +$V{Variable_2} + $V{Variable_3}]]></initialValueExpression> </variable> <title> <band height="79" splitType="Stretch"> <textField pattern="#,##0.000"> <reportElement x="240" y="20" width="100" height="30" uuid="ff21d30b-5d5a-4e20-8d5d-1d66da270d5c"/> <textFieldExpression><![CDATA[$V{total}]]></textFieldExpression> </textField> </band> </title></jasperReport>[/code] Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now