A Strange Number
Posted by andy in : Agile on November 13, 2006. There are no responses »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!
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); } }

