Any common alternatives to java.text.DecimalFormat

J

Jim Cobban

Since there appears to be no possibility that Sun will agree to any changes
to the functionality of java.text.DecimalFormat despite its manifold
deficiencies, are there any common workarounds or alternatives?

Examples of deficiencies:

1) Output is variable in width whereas many applications require fixed width
columns.
2) Negative values are always displayed in a wider field than positive
values.
3) No support for explicitly identifying positive values, for example with a
+ sign.
4) No support for grouping fractional digits.
5) Basically no equivalent to formatting that has been available in
predecessor languages all the way back to FORTRAN and COBOL.
 
P

Patricia Shanahan

Jim said:
Since there appears to be no possibility that Sun will agree to any changes
to the functionality of java.text.DecimalFormat despite its manifold
deficiencies, are there any common workarounds or alternatives?

Examples of deficiencies:

1) Output is variable in width whereas many applications require fixed width
columns.
2) Negative values are always displayed in a wider field than positive
values.
3) No support for explicitly identifying positive values, for example with a
+ sign.
4) No support for grouping fractional digits.
5) Basically no equivalent to formatting that has been available in
predecessor languages all the way back to FORTRAN and COBOL.

I don't understand your points 2 and 3.

new DecimalFormat("+0.0;-0.0") formats 3.0 as "+3.0" and -3.0 as "-3.0".
The positive value does have an explicit + sign, and they are the same
width for the same absolute value.

Patricia
 
J

John C. Bollinger

Jim said:
Since there appears to be no possibility that Sun will agree to any changes
to the functionality of java.text.DecimalFormat despite its manifold
deficiencies, are there any common workarounds or alternatives?

The Java 1.5 platform library has java.util.Formatter, which may do
things you like better. Or you can always write your own Format.
Depending on you specific needs, it might be more convenient in any
particular case to format your numbers more-or-less manually in a
StringBuffer / StringBuilder.
 
R

Roedy Green

1) Output is variable in width whereas many applications require fixed width
columns.

The way this is typically handled in a gui is not with leading spaces,
but with right field justification. Then it works even with a variable
pitch font.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,020
Latest member
GenesisGai

Latest Threads

Top