Created
August 4, 2011 17:39
-
-
Save oscarryz/1125723 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
if d[i]=123056 then the output should be 123,056.00 not 123,56._