Re: left-padding ints
Ike <rxv@xxxxxxxxxxx> wrote:
> Is there something in the API for left-padding an int with, say, 0's when
> converting to a String, such that, say 1 becomes "01" ? -Ike
Yep. See java.text.DecimalFormat or java.text.NumberFormat. For
DecimalFormat, simply use '0' characters instead of '#' characters in
the pattern. For NumberFormat, use setMinimumIntegerDigits. The
difference between the two is that NumberFormat is more flexible. If
you're sure that you want to display the result in a decimal number
system regardless of locale, then use DecimalFormat instead.
--
www.designacourse.com
The Easiest Way To Train Anyone... Anywhere.
Chris Smith - Lead Software Developer/Technical Trainer
MindIQ Corporation
.
Relevant Pages
- Re: DecimalFormat
... In general, do not call the DecimalFormat constructors directly, ... since the NumberFormat factory methods may return subclasses ... Umso unverständlicher, dass SUN diese Konstruktoren ... gleich zur Benutzung der Factory zu zwingen. ... (de.comp.lang.java) - Re: Help with Decimals and Rounding
... NumberFormat vs DecimalFormat -- NumberFormat is an abstract class but ... it does provide convenient methods to create DecimalFormat instances. ... Rounding -- As you can see from a close look at the above code (I changed ... rounded up and discarded amounts < 5 are rounded down, ... (comp.lang.java.help) - Re: DecimalFormat
... In general, do not call the DecimalFormat constructors directly, ... since the NumberFormat factory methods may return subclasses ... Konsequent wäre hier IMHO ... gleich zur Benutzung der Factory zu zwingen. ... (de.comp.lang.java) - instanceOf operator new bie question
... I am using Java 1.4.2.x ... ((DecimalFormat) ... What does "df instanceof DecimalFormat" really mean? ... NumberFormat can be converted to DecimalFormat? ... (comp.lang.java.programmer) - Re: How do I get more than 255 characters to display in a merged cell
... Try changing the numberformat from Text to General. ... If you have lots and lots of text, you may have to add alt-enters every 80-100 ... characters to see all the text. ... Dave Peterson ... (microsoft.public.excel.setup) |
|