NumberUtils { public static boolean isLikelyDouble(long value) { if (value == canonicalDoubleNaN || value == maxDouble || value == piDouble || value == eDouble) { return true; } if (value == Long.MAX_VALUE || value == Long.MIN_VALUE) { return false; } double doubleValue = Double.longBitsToDouble(value); if (Double.isNaN(doubleValue)) { return false; } String asLong = format.format(value); String asDouble = format.format(doubleValue); int decimalPoint = asDouble.indexOf('.'); int exponent = asDouble.indexOf("E"); int zeros = asDouble.indexOf("000"); if (zeros > decimalPoint && zeros < exponent) { asDouble = asDouble.substring(0, zeros) + asDouble.substring(exponent); } else { int nines = asDouble.indexOf("999"); if (nines > decimalPoint && nines < exponent) { asDouble = asDouble.substring(0, nines) + asDouble.substring(exponent); } } return asDouble.length() < asLong.length(); }  static boolean isLikelyFloat(int value); static boolean isLikelyDouble(long value);  }
@Test public void isLikelyDoubleTest() { Assert.assertTrue(NumberUtils.isLikelyDouble(Double.doubleToRawLongBits(1.23f))); Assert.assertTrue(NumberUtils.isLikelyDouble(Double.doubleToRawLongBits(1.0f))); Assert.assertTrue(NumberUtils.isLikelyDouble(Double.doubleToRawLongBits(Double.NaN))); Assert.assertTrue(NumberUtils.isLikelyDouble(Double.doubleToRawLongBits(Double.NEGATIVE_INFINITY))); Assert.assertTrue(NumberUtils.isLikelyDouble(Double.doubleToRawLongBits(Double.POSITIVE_INFINITY))); Assert.assertTrue(NumberUtils.isLikelyDouble(Double.doubleToRawLongBits(1e-30f))); Assert.assertTrue(NumberUtils.isLikelyDouble(Double.doubleToRawLongBits(1000f))); Assert.assertTrue(NumberUtils.isLikelyDouble(Double.doubleToRawLongBits(1f))); Assert.assertTrue(NumberUtils.isLikelyDouble(Double.doubleToRawLongBits(-1f))); Assert.assertTrue(NumberUtils.isLikelyDouble(Double.doubleToRawLongBits(-5f))); Assert.assertTrue(NumberUtils.isLikelyDouble(Double.doubleToRawLongBits(1.3333f))); Assert.assertTrue(NumberUtils.isLikelyDouble(Double.doubleToRawLongBits(1.33333f))); Assert.assertTrue(NumberUtils.isLikelyDouble(Double.doubleToRawLongBits(4.5f))); Assert.assertTrue(NumberUtils.isLikelyDouble(Double.doubleToRawLongBits(.1f))); Assert.assertTrue(NumberUtils.isLikelyDouble(Double.doubleToRawLongBits(50000f))); Assert.assertTrue(NumberUtils.isLikelyDouble(Double.doubleToRawLongBits(Double.MAX_VALUE))); Assert.assertTrue(NumberUtils.isLikelyDouble(Double.doubleToRawLongBits(Math.PI))); Assert.assertTrue(NumberUtils.isLikelyDouble(Double.doubleToRawLongBits(Math.E))); Assert.assertFalse(NumberUtils.isLikelyDouble(0)); Assert.assertFalse(NumberUtils.isLikelyDouble(1)); Assert.assertFalse(NumberUtils.isLikelyDouble(10)); Assert.assertFalse(NumberUtils.isLikelyDouble(100)); Assert.assertFalse(NumberUtils.isLikelyDouble(1000)); Assert.assertFalse(NumberUtils.isLikelyDouble(1024)); Assert.assertFalse(NumberUtils.isLikelyDouble(1234)); Assert.assertFalse(NumberUtils.isLikelyDouble(-5)); Assert.assertFalse(NumberUtils.isLikelyDouble(-13)); Assert.assertFalse(NumberUtils.isLikelyDouble(-123)); Assert.assertFalse(NumberUtils.isLikelyDouble(20000000)); Assert.assertFalse(NumberUtils.isLikelyDouble(2000000000)); Assert.assertFalse(NumberUtils.isLikelyDouble(-2000000000)); Assert.assertFalse(NumberUtils.isLikelyDouble(Integer.MAX_VALUE)); Assert.assertFalse(NumberUtils.isLikelyDouble(Integer.MIN_VALUE)); Assert.assertFalse(NumberUtils.isLikelyDouble(Short.MIN_VALUE)); Assert.assertFalse(NumberUtils.isLikelyDouble(Short.MAX_VALUE)); }