Jump to content
We've recently updated our Privacy Statement, available here ×

combining variables and static text


rufus2

Recommended Posts

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

Link to comment
Share on other sites

  • Replies 2
  • Created
  • Last Reply

Top Posters In This Topic

Popular Days

Top Posters In This Topic

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

Link to comment
Share on other sites

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

 

 

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