mmans Posted June 12, 2013 Share Posted June 12, 2013 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 More sharing options...
Ankur Gupta Posted June 13, 2013 Share Posted June 13, 2013 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.StringThis will fix the issue. Thanks,Ankur Link to comment Share on other sites More sharing options...
Thomas Zimmer Posted June 13, 2013 Share Posted June 13, 2013 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-javaor here:http://docs.oracle.com/javase/1.5.0/docs/api/java/util/Formatter.htmlHowever, 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 likenew 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, Thomashttp://www.thomaszimmer.net Link to comment Share on other sites More sharing options...
mmans Posted June 13, 2013 Author Share Posted June 13, 2013 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" :DRegards,Marco Link to comment Share on other sites More sharing options...
info_1205 Posted May 4, 2022 Share Posted May 4, 2022 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 More sharing options...
Recommended Posts
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 accountSign in
Already have an account? Sign in here.
Sign In Now