A Strange Number
Posted by andy in : Agile on November 13, 2006.I came across a very strange number today while writing some unit tests. Apparently Java thinks “10WTF?” is a perfectly valid number and does not throw a ParseException when you try converting the string to a number.
Here is the unit test to prove it!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 | import junit.framework.TestCase; import java.text.DecimalFormat; import java.text.ParseException; public class StrangeNumberTest extends TestCase { public void testWierdJavaNumber() throws ParseException { DecimalFormat format = new DecimalFormat("##,###.00"); assertEquals("Amazing, but true", 10, (Long) format.parse("10WTF?"), 0); } } |
