Thank you Cyntia,
I have read this docs and found that it is easier to convert
leading zeroes to spaces by myself.
Regards,
Jacob Nikom
Cynthia Jeness wrote:
>
> Jacob,
>
> I also think that this should be part of standard Java; however, here is
> a paragraph from the Javadoc supplied with Java 2 for the NumberFormat
> class:
>
> -------Extract from JavaDoc----------
> You can also use forms of the parse and format methods with ParsePosition
> and FieldPosition to allow you to:
>
> progressively parse through pieces of a string
> align the decimal point and other areas
>
> For example, you can align numbers in two ways:
>
> 1.If you are using a monospaced font with spacing for alignment, you
> can pass the FieldPosition in your format call, with
> field = INTEGER_FIELD. On output, getEndIndex will be set to the
> offset between the last character of the integer and
> the decimal. Add (desiredSpaceCount - getEndIndex) spaces at the
> front of the string.
> 2.If you are using proportional fonts, instead of padding with
> spaces, measure the width of the string in pixels from the start to
> getEndIndex. Then move the pen by (desiredPixelWidth -
> widthToAlignmentPoint) before drawing the text. It also works
> where there is no decimal, but possibly additional characters at
> the end, e.g., with parentheses in negative numbers: "(12)"
> for -12.
> ---------------------------------
>
> Cynthia Jeness
>
> Jacob Nikom wrote:
>
> > Thank you very much Juergen,
> >
> > It sounds like there is no such functionality in "standard" Java
> > at all - this is strange. To be able to right-justified numbers
> > is the basic requirement for any numerical output.
> >
> > It is not a problem to write a program which does it - actually
> > it is quite easy to convert leading zeroes into spaces. I wanted
> > to have "pure" Java solution in the sense that people should not
> > write what is already written (or should be written).
> >
> > If I find "standard Java" solution I will post it.
> >
> > Regards,
> >
> > Jacob Nikom
> >
> > Juergen Kreileder wrote:
> > >
> > > >>>>> Jacob Nikom writes:
> > >
> > > Jacob> I used DecimalFormatter class:
> > >
> > > Jacob> DecimalFormat myFormatter = new DecimalFormat("0000");
> > > Jacob> String iString = myFormatter.format(myNumber);
> > >
> > > Jacob> However, what I got was:
> > >
> > > Jacob> 0001
> > > Jacob> 0012
> > > Jacob> 0344
> > > Jacob> 1557
> > >
> > > Jacob> (The pattern "####" did not work at all)
> > >
> > > Jacob> Do you know, how I can get rid of leading zeroes and get
> > > Jacob> my formatting correctly?
> > >
> > > I never tried it but maybe this does what you want:
> > >
> > > http://www2.jps.net/~adahlman/programs/PaddedDecimalFormat.java
> > > http://pws.prserv.net/ad/programs/PaddedDecimalFormat.html (Javadoc)
> > >
> > > Juergen
> > >
> > > --
> > > Juergen Kreileder, Blackdown Java-Linux Team
> > > http://www.blackdown.org/java-linux.html
> >
> > ----------------------------------------------------------------------
> > To UNSUBSCRIBE, email to [EMAIL PROTECTED]
> > with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]
----------------------------------------------------------------------
To UNSUBSCRIBE, email to [EMAIL PROTECTED]
with a subject of "unsubscribe". Trouble? Contact [EMAIL PROTECTED]