• Post Reply Bookmark Topic Watch Topic
  • New Topic

Left padding numbers  RSS feed

 
Edward Nunez
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey guys.
Anyone know of a way to place leading zeros onto numbers without having to convert them to strings? Is such a thing possible?

Edward.
 
Winston Gutkowski
Bartender
Posts: 10575
66
Eclipse IDE Hibernate Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Edward Nunez wrote:Anyone know of a way to place leading zeros onto numbers without having to convert them to strings?

Why would you want to? Numerically, a leading '0' means nothing (both literally and figuratively), so the only place they have any relevance is in a String. And if that's you're question then the answer is 'yes' - in fact there are many ways to do it.

Winston
 
Edward Nunez
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Well, I'd like to represent minuets in a drop down menu. You're right Winston, I don't really need this--it would only save the trouble of having to parse my Strings back into numbers. Just curious is about it is all.
 
Steve Fahlbusch
Bartender
Posts: 612
7
Mac OS X Python
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Greetings,

Just a hint here…… when you display something, it is a string not a number. Numbers are internal to the computer - input / output (at least for human device - keyboard, console …..) they are strings (or at least characters, not numbers.

-steve
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Minuets? Surely you mean minutes

Go to the Java Tutorials and use ctrl‑F‑“Formatting” Read both hits. Also read about the Formatter class (which may not be easy to read, I am afraid).
 
Edward Nunez
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Right you all are. Although, Steve, If I make a combo box with an int array and display that combo box on a frame, are they still not displayed as int options?

To take a few step backs here, what I'm doing is taking time input from three combo boxes: hours, minutes, and am/pm. If you guys know a significantly easier way of getting that from the user with Swing, do tell.
 
Campbell Ritchie
Marshal
Posts: 56570
172
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Is that the same question or a different question?
 
Edward Nunez
Ranch Hand
Posts: 39
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Regarding the int array, it's the same question. Although I wanted to say that I'm displaying a combo box of numbers, rather than printing to the console.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!