Jump to content

Textfield pattern


Recommended Posts

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

Link to comment
Share on other sites

  • Replies 4
  • Created
  • Last Reply

Top Posters In This Topic

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. 




Link to comment
Share on other sites

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:


or here:


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}


"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


Link to comment
Share on other sites

  • 8 years later...

The post of @Ankur Gupta helped me already, but if you want a specific language format you need to add the locale:

"The amount of " + new java.text.DecimalFormat("#,##0.00", new java.text.DecimalFormatSymbols(java.util.Locale.GERMANY)).format($F{amount}) + " will be debited from your account."// $F{amount} = 1000.00 the output will be:// The amount of 1.000,00 will be debited from your account.[/code]

Hope that helps somebody...

ps: here as jdoodle.com/a/4LWs for live testing.

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