Textfield pattern

0

Hi There!

I'm trying to put a textfield in static text. The final text has to be like this: "The amount of $123.45 will be debited from your account."

My first try was to create 1 textfield with this expression: "The amount of "+ $F{amount} +"will be debited from your account."

Generally, this works. But I want to format the $F{amount} as a currency. Without a pattern the number is shown as 123.450000000000.
But because I put static text in the textfield expression, the datatype is handled as "String" not as "Double".

When I use the contruction [Static Text][Textfield][Static text], I get a lot of white space before and after the amount.....

How could I fix this?

Thanks a lot in advance!!!!!!

Kind regards,
Marco Mans

mmans's picture
9
Joined: Aug 5 2010 - 10:43pm
Last seen: 3 years 3 months ago

3 Answers:

1

Hi mmans ,

What you can do to fix this is, set the expression for 1 textfield as :

 "The amount of  "+new java.text.DecimalFormat("¤ #,##0.00").format($F{amount}) + "  will be debited from your account."

The field which you use to display this would be a single textfield , with no changes in pattern and the Expression class would be java.lang.String

This will fix the issue. 

Thanks,

Ankur

 

Ankur Gupta's picture
Joined: Jan 21 2013 - 10:36pm
Last seen: 10 months 3 days ago
1

Sorry, but you DO NOT put "put a textfield in static text"... What you are doing is concatenating a literal text with a field of type double (or similar), and present the result of that expression in a text field.

What you have to do is to format the number within the text fields expression. There are different possibilities of doing that, depending on the java version you are using.

Have a look here:

http://stackoverflow.com/questions/50532/how-do-i-format-a-number-in-java

or here:

http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Formatter.html

However, it should result in an exspression for your text field like:

String.format("The amount of $%5.2f will be debited from your account.", $F{theamount}

or:

"The amount of $" + $P{mynumformatter}.format(dd)).doubleValue() + "will be...."

where $P{mynumformatter} has a default value like

new DecimalFormat( "#,###,###,##0.00" )

Is far as I remember, the report has a default parameter "REPORT_FORMATTER" which can do similar.

I hope this helps.

Cheers, Thomas

http://www.thomaszimmer.net

Thomas Zimmer's picture
Joined: Oct 2 2012 - 1:35am
Last seen: 3 days 19 hours ago
0

Thanks for both answers. I got it working now.

When using Japser I still have to get used to the fact, that I can use "The-Standard-Java-Way" (tm) :D

Regards,

Marco

mmans's picture
9
Joined: Aug 5 2010 - 10:43pm
Last seen: 3 years 3 months ago
Feedback