Jump to content
Changes to the Jaspersoft community edition download ×

Divide By Zero Exception


manikkumar

Recommended Posts

Hi,

I have been working on Jasper Reports since a month now. This forum has been really helpful in solving all my problems till now.

But I couldn't find any solution for the "/ by Zero" exception I am getting right now. In my report I am dividing two bigdecimals and I want to display the result as a percentage on my report.

The error I am getting is in the code section

where $V{Sum_Infeeds}.divide($V{Sum_Total},2,BigDecimal.ROUND_HALF_UP) is the variable I have defined.$V{Sum_Total} & $V{Sum_Infeeds} are also variables, which run over the report to find out the sum of their respective columns.

I am getting a '/ by zero exception'; however, I have checked that the value of my variable is not actually zero. Also, the report runs good on one of the database but throws an exception on the other database. Does anybody have an idea as to why is this happening??

 

Code:
Error filling print... Error evaluating expression :     Source text : $V{Sum_Infeeds}.divide($V{Sum_Total},2,BigDecimal.ROUND_HALF_UP)net.sf.jasperreports.engine.fill.JRExpressionEvalException: Error evaluating expression :     Source text : $V{Sum_Infeeds}.divide($V{Sum_Total},2,BigDecimal.ROUND_HALF_UP)     at net.sf.jasperreports.engine.fill.JREvaluator.evaluateEstimated(JREvaluator.java:257)     at net.sf.jasperreports.engine.fill.JRCalculator.evaluateEstimated(JRCalculator.java:565)     at net.sf.jasperreports.engine.fill.JRCalculator.estimateVariables(JRCalculator.java:169)     at net.sf.jasperreports.engine.fill.JRFillDataset.next(JRFillDataset.java:773)     at net.sf.jasperreports.engine.fill.JRBaseFiller.next(JRBaseFiller.java:1413)     at net.sf.jasperreports.engine.fill.JRVerticalFiller.fillReport(JRVerticalFiller.java:111)     at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:899)     at net.sf.jasperreports.engine.fill.JRBaseFiller.fill(JRBaseFiller.java:802)     at net.sf.jasperreports.engine.fill.JRFiller.fillReport(JRFiller.java:63)     at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:421)     at net.sf.jasperreports.engine.JasperFillManager.fillReport(JasperFillManager.java:251)     at com.jaspersoft.ireport.designer.compiler.IReportCompiler.run(IReportCompiler.java:896)     at org.openide.util.RequestProcessor$Task.run(RequestProcessor.java:561)     at org.openide.util.RequestProcessor$Processor.run(RequestProcessor.java:986) Caused by: java.lang.ArithmeticException: / by zero     at java.math.BigDecimal.divide(Unknown Source)     at Summary32By32HOUR_1246393018792_406802.evaluateEstimated(Summary32By32HOUR_1246393018792_406802:636)     at net.sf.jasperreports.engine.fill.JREvaluator.evaluateEstimated(JREvaluator.java:246)     ... 13 more Print not filled. Try to use an EmptyDataSource... 
Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

This is a general JasperReports issue.

 

You are probably including this calculation in a group, and there may be some cases were the value is 0. Try making the expression conditional, like: ($V{B} != 0 ? ($V{A}/$V{B} * 100) : 0 )

 

Sherman

Jaspersoft

Link to comment
Share on other sites

  • 1 month later...

 have similar problem

 

I am pulling two fields from DB:

 

<field name="revenue" class="java.lang.Double"/>

<field name="trans_number" class="java.lang.Integer"/>

 
and trying to do the following:
 
<textField pattern="#,##0.00">
<reportElement x="163" y="0" width="125" height="30"/>
<textElement/>
<textFieldExpression class="java.lang.String"><![CDATA[$F{revenue}/$F{trans_number}]]></textFieldExpression>
</textField>
 
I get the error attached below during report compilation.
 
Any help appreciated.
 
Denys 
 

 

Code:


Post Edited by denys at 08/07/2009 15:43
Link to comment
Share on other sites

found this solution but it still seems a bit heavy:

 

<textFieldExpression class="java.lang.Double"><![CDATA[java.lang.Double.valueOf($F{revenue}.doubleValue()/$F{trans_number}.intValue())]]></textFieldExpression>

 

Link to comment
Share on other sites

  • 4 years later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...