• 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
  • Ron McLeod
  • Paul Clapham
  • Tim Cooke
  • Devaka Cooray
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Rob Spoor
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Mikalai Zaikin
Bartenders:
  • Carey Brown
  • Roland Mueller

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"
 
I have always wanted to have a neighbor just like you - Fred Rogers. Tiny ad:
We need your help - Coderanch server fundraiser
https://coderanch.com/wiki/782867/Coderanch-server-fundraiser
reply
    Bookmark Topic Watch Topic
  • New Topic