• Post Reply Bookmark Topic Watch Topic
  • New Topic

append 0 with 0 to 9(0 as 00, 1 as 01...., 9 as 09) ?  RSS feed

 
kri shan
Ranch Hand
Posts: 1489
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How should append 0 with 0 to 9(0 as 00, 1 as 01....,9 as 09) ?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24217
38
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
There are so many different things you might mean here, that I can't give you a very specific answer to your question. It's possible, though, that the class java.text.DecimalFormat is what you're looking for -- go check it out.
 
Campbell Ritchie
Marshal
Posts: 56546
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
. . . or using the %02d tag in Formatter.format or a similar method?
 
kri shan
Ranch Hand
Posts: 1489
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Ernest & Campbell, I have tried both the ways..... java.text.DecimalFormat / using the %02d tag in Formatter.format. But it gives String result. If i convert String 02 to short it truncates 0 and gives only 2.

I am converting short 2 to short 02. Any inputs ?
 
Henry Wong
author
Sheriff
Posts: 23295
125
C++ Chrome Eclipse IDE Firefox Browser Java jQuery Linux VI Editor Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am converting short 2 to short 02. Any inputs ?


A short variable hold a whole number in the space of 16 bits -- there is no format. There is *no* such a thing as converting a short 2 to a short 02.

The only reason that you would need a format, is so that you can send it to an location, such as print it to the screen or a DB. As such, you will have to convert it to a string, using DecimalFormat or Formatter to format the string.

Henry
[ February 04, 2007: Message edited by: Henry Wong ]
 
Consider Paul's rocket mass heater.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!