Jump to content
JasperReports Library 7.0 is now available ×

Error casting String to a BigDecimal


Yippie

Recommended Posts

Hello,

 

I'm encountering the following error when I run a report. My deployment server key info is:

 

Suse Linux Enterprise Edition

Apache Tomcat 5.5.17

Java 1.5

Jasper Report version 1.2.5

I created the report using iReport 1.2.5.

 

The error is:

javax.faces.el.EvaluationException: java.lang.Exception: Error evaluating expression : Source text : new BigDecimal($F{lastYearSales})

 

Here is the situation. The report gets it's data from a custom Java Bean that returns a array of String objects. The report is a purchase history report that breaks on the Customer's name. Initially, no sub-totals were needed, but now the user's want to see a sub-total. Rather than rewrite the bean to return a multi data type array, we just removed the currency format from the dollar Strings and I am trying to case the String object to a BigDecimal object using the following in my Variable Expression: new BigDecimal($F{dollars}). I have even tried: new java.math.BigDecimal($F{dollars}). Both work just fine when I run the report from iReport. When I run the report from my JSF application, I get the aforementioned error.

 

Does anyone have any suggestions?

 

Thanks in advance.

 

Craig...

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

we made a helper class for that, because the expression were too long otherwise:

 

just make a class that is within the classpath at runtime:

 

as FieldExpression I use:

 

Code:
MathLib.stringToBigDecimal($F{StringFieldThatContainsBD})

 

 

Code:
[code]

....

public static BigDecimal stringToBigDecimal(String str) {
return MathLib.stringToBigDecimal(str, "###,###,##0.00", 2);
}

public static BigDecimal stringToBigDecimal(String str, String format, int nachkommastellen) {
if (str.length() > 0) {
DecimalFormat df = new DecimalFormat(format);
Number x;
try {
x = df.parse(str);
BigDecimal y = new BigDecimal(Double.toString(x.doubleValue()));
y = round(y, nachkommastellen);
return y;
}
catch (ParseException e) {
return new BigDecimal(0);
}
}
else {
return new BigDecimal(0);
}
}
}

public static BigDecimal round(BigDecimal zahl, int nachkommastellen) {
if (zahl == null) {
zahl = BigDecimal.ZERO;
}
return zahl.setScale(nachkommastellen, BigDecimal.ROUND_HALF_UP);
}
....

 

hth

C-Box

Post edited by: CBox, at: 2006/11/09 16:16

Link to comment
Share on other sites

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...