combining variables and static text

Hi Everyone,

I have a variable expression that is a java.math.BigDecimal expression class and is defined as follows:

new java.math.BigDecimal($F{loan_amount}.intValue()/100

When I place this variable into my report, I can assign a currency pattern to the variable without issue.  However, I would like to combine this varaible into a sentence so that it reads "Your loan amount is equal to $xx,xxxx". 

When I attempt to simply add the text to the text field (i.e. "Your loan amount is equal to "+$V{OrigLoanBal}, I receive an error when IReport attempts to evaluate the expression. 

I believe that I need to convert the BigDecimal to a string but  unfortunately don't know Java at all (have been learning through osmosis on this forum) and can't find any similar statements if I were to try to use Groovy.  Does anyone have any thoughts?

Second - can anyone recommend a good book or web site that shows examples of java expressions or groovy expressions.  I have the Definitive Guide to IReport which has proved helpful on many items - but it unfortunately assumes that the reader has a good knowledge of Java.  I've read countless sites that discuss java programming, but most of those seem to be overkill for what I'm looking for.  Any thoughts?

Thank you [again] for your help,

R

rufus2's picture
264
Joined: Oct 8 2008 - 8:40pm
Last seen: 14 years 11 months ago

2 Answers:

Hi Rufus, Try... "My little sentince $" + new BigDecimal($F{loan_amount).intValue()/100).toString() + " and some moer words" Check out the Java API. Its pretty straight forward for these sort of conversions. Most objects will have a toString() method. Also since you are using a BigDecimal I am thinking you'll need the decimal places returned as well...? What you have here will round to the nerest whole number. Again check out the Java API. You'll need to either use the devide() method or use $F{loan_amount}.doubleValue(). Cheers
lukus's picture
351
Joined: Sep 18 2007 - 1:03pm
Last seen: 10 years 1 week ago

Lukus - thanks for your quick reply and the recommendation for the Java API site. 

The method you suggested allowed me to combine the text and the field value but I wasn't able to format the number within the string as currency.

However, I was able to find (through the API and these forums) a method to do so that seems to work:

"the first part of the sentence I wanted " + NumberFormat.getCurrencyInstance().format($F{OrigLoanBal}) + "the last part of the sentence I wanted."

Thanks again for your help - your suggestion broke my log jam.

R

 

 

rufus2's picture
264
Joined: Oct 8 2008 - 8:40pm
Last seen: 14 years 11 months ago
Feedback