Andy Pols Geek, Entrepreneur

A Strange Number

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's 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);
    }
}
comments powered by Disqus