• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Right Justify---zero fill

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have the user filling in a HTML text box in my JSP a serial number string like 1234.
The length of the field is zero filled in my database so I need to put a 0 in front like 01234. Is this possible?

I am building a SQL statement with the user selects like this:
sysserno = request.getParameter("sysserno");
sqlValue=sysserno;
sqlName="SYSNO";
sqlCondition=sysserCondition;
buildSQL();


what can I do to sysserno to make sure it's 5 characters zero filled?
 
author
Posts: 14112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Take a look at the DecimalFormat class.
 
Mike Kay
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thnx
 
(instanceof Sidekick)
Posts: 8791
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Is that a String (char of some kind) in the database? For a quick zero pad to a fixed length - say five as you showed above - you can do:

String padded = ( "00000" + input ).substring( input.length() );

If you do this a lot you might make a utility method that takes a length and a pad character. This signature come from the REXX language; right is short for right justify. In REXX right() left() and center() also truncate inputs that are too long so you can make neat columnar output.

right( input, length, pad )
right( "123", 5, "0" ) -> "00123"
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic