wood burning stoves 2.0*
The moose likes JSF and the fly likes Padding for Numeric values Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » JSF
Bookmark "Padding for Numeric values" Watch "Padding for Numeric values" New topic
Author

Padding for Numeric values

Ganesh Podaralla
Greenhorn

Joined: Feb 22, 2010
Posts: 23
Hello ranchers,

I have defined my managed bean variables as Wrappers (Integer, Long, Double etc). I would like to left-pad zeros to the numbers to be displayed on the JSF with Facelets page. Please let me know the better ways to left-pad zeros to numeric values without changing the variables to data type String. I am using Richfaces in my project.

Thanks,
Ganesh
Davie Lin
Ranch Hand

Joined: Aug 05, 2007
Posts: 294
Have you look into



It's got a method for leftPad

Althought it use String, but you can always convert it back to the Wrapper type that you're using in the managed bean.

Sue Temple
Greenhorn

Joined: May 01, 2010
Posts: 19



will print 00055.

Is this what you need?
Ganesh Podaralla
Greenhorn

Joined: Feb 22, 2010
Posts: 23
No..I am searching for a tag in JSF/Richfaces to pad automatically on the page. If not, I may need to use a custom converter to pad zeros. Please let me know if there is any existing tag I can use on the page (.xhtml).
Sue Temple
Greenhorn

Joined: May 01, 2010
Posts: 19

Try to tweak this, I am guessing this will do it -

Ganesh Podaralla
Greenhorn

Joined: Feb 22, 2010
Posts: 23
Thanks Sue Temple..
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Padding for Numeric values
 
Similar Threads
Format the number in java
Padding a String
format exception
How to get ASCII Value
read() in File class