manit.deepak Posted June 18, 2016 Share Posted June 18, 2016 Our Requirement is to achieve padding with '0' for Number field and '#' to Varchar field:We have a TextField of width=100. When the report is generated, dynamically data is populated into that field.Let the data populated length be 20. We have right aligned the textfield.Now the problem is we want to prepend 100-20= 80 Zeros' to the data. How we can achieve the same using Jasper or Java programming?Thanks-Deepak Dewangan Link to comment Share on other sites More sharing options...
javier.ggi90 Posted June 20, 2016 Share Posted June 20, 2016 Make use of String.format() function.String: String.format("%10s", field) will pad spaces at the left of the string. To pad them to the right use String.format("%-10s", field). The amount of spaces to be added will be {10 - field length}Integer: String.format("%06d", field) will pad {6 - field length} zeros to the left, in this case. It is important to note that the field HAS to be an Integer of any type. Without the zero, the output will be with padded spaces 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