Jump to content
We've recently updated our Privacy Statement, available here ×

How to achieve padding( with zero) on textfield.


manit.deepak

Recommended Posts

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

  • Replies 1
  • Created
  • Last Reply

Top Posters In This Topic

Top Posters In This Topic

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

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