Roedy asks:
When you do that, what sorts of string are acceptable. Does it insist
on the comma?
It's actually very forgiving. It seems to completely ignore
the commas, the number of digits between them, etc. I wrote
this quick test:
public class NumberTest {
public static void main( String args[] ) {
DecimalFormat formatter = new DecimalFormat( "#,##0" );
int parsed;
String formatted;
for( int i = 0; i < args.length; i++ ) {
try {
parsed = formatter.parse( args
).intValue();
formatted = formatter.format( parsed );
System.out.println( "Original = " +
args +
", parsed = " + parsed +
", formatted = " + formatted );
}
catch( Exception e ) {
System.err.println( e.toString() );
}
}
}
}
Here's a test run:
$ java NumberTest 1,000 1000 4,1567,890 4567890 1,34546
Original = 1,000, parsed = 1000, formatted = 1,000
Original = 1000, parsed = 1000, formatted = 1,000
Original = 4,1567,890, parsed = 41567890, formatted = 41,567,890
Original = 4567890, parsed = 4567890, formatted = 4,567,890
Original = 1,34546, parsed = 134546, formatted = 134,546
$
So it's more powerful on the formatting end than the parsing one.
Fair enough!