Skip to content

Instantly share code, notes, and snippets.

@oscarryz
Created August 4, 2011 17:39
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save oscarryz/1125723 to your computer and use it in GitHub Desktop.
Save oscarryz/1125723 to your computer and use it in GitHub Desktop.
import java.text.DecimalFormat;
class F {
public static void main( String ... args ) {
DecimalFormat f = new DecimalFormat("000,000.00");
double [] d = {
0.01,
0.12,
123456,
123456.78,
1234,
1234.56
};
String [] expected = {
"______._1",
"______.12",
"123,456.__",
"123,456.78",
"__1,234.__",
"__1,234.56"
};
for( int i = 0; i < d.length ; i++ ) {
assert f.format( d[i] ).replaceAll("0","_").replaceAll("_,_","__").equals( expected[i] );
}
}
}
// test it with java -ea F
@hari2
Copy link

hari2 commented Dec 25, 2016

if d[i]=123056 then the output should be 123,056.00 not 123,56._

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment