swarupakp Posted November 11, 2009 Share Posted November 11, 2009 I m using iReport 3.0.0The value which is of Double type having 10.566899952 .I want to convert this value to 10.57. How to roundfig the value in jasper reports..If anybody knows the answer pls help me.. Link to comment Share on other sites More sharing options...
Giulio Toffoli Posted November 12, 2009 Share Posted November 12, 2009 just apply a pattern to the textfield showing the number, or use the expression: new java.text.DecimalFormat("#,##0.00").format( $F{my_number} )Giulio Link to comment Share on other sites More sharing options...
swarupakp Posted November 12, 2009 Author Share Posted November 12, 2009 Thanq.Its Working..I have given in iReport Pattern as ###0.00..If it is double its working..But some times i may have String.B'cozI m converting field value (Inches to Cms) .So for that if i am having the in field i need to multiply with 2.54.But if the field value will be null that time its giving Null Pointer Exception..So to avoid that i can convert null to 0 then i can multiply..But we shouldnt show 0 in that place..If its null i have to show empty string over there..So if i m taking the field in String type..I can apply Blank when null..But the format is not coming i am doing like below.(new Double(Double.parseDouble($F{Inches})*2.54).toString().The result is String type.But i want to show in ###0.00 this format..But its not roundfig the value after the point..Its showing 111.1258 .But i want the value like 111.13.If it is string its not converting..I knew we cannot truncate with String type values..But why the pattern is available if the data is in String type.. Link to comment Share on other sites More sharing options...
Giulio Toffoli Posted November 12, 2009 Share Posted November 12, 2009 just check for null: ( $F{Inches} != null ) ? (new Double(Double.parseDouble($F{Inches})*2.54) ) : nullThe number pattern is applied only to textfield showing numbers.Giulio 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