Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!

J R Quigley

Greenhorn
+ Follow
since Aug 01, 2002
Cows and Likes
Cows
Total received
0
In last 30 days
0
Total given
0
Likes
Total received
0
Received in last 30 days
0
Total given
0
Given in last 30 days
0
Forums and Threads
Scavenger Hunt
expand Ranch Hand Scavenger Hunt
expand Greenhorn Scavenger Hunt

Recent posts by J R Quigley

Neat program. But surely there must be a shorter way to replace leading zeroes in a number with printing blanks, something like Cobol does with PIC ZZZ,ZZ9.
Should we use DecimalFormat or some other class to do this?
Help.
19 years ago
I am having the same problem as that posted by Cata Lin. I am trying to list an integer with a fixed number of positions on the screen (such as three) where leading zeroes appear as spaces. I tried the following formats:
DecimalFormat df1 = new DecimalFormat("###,##0");
DecimalFormat df3 = new DecimalFormat("##0");
However what I get instead are simply truncated positions so that numbers don't line up on the right when the output goes from two to three digits, for example.
I've searched the Sun Java API and also the Java Ranch archives and I cannot find a clear solution to this problem.
Is there a clear and simple way to do this?
19 years ago