/** * @test * @bug 4428022 4511638 6575880 4191279 * @summary Float/Double.toString should not output trailing zeros */ public class FloatDoubleTrailingZeros { public static void main(String[] args) throws Exception { String s; // Test Float.toString s = Float.toString(0.001f); if (!s.equals("0.001")) { System.out.println ("Float.toString(0.001f) = " + s); throw new Exception("Float.toString(\"0.001\") != \"0.001\""); } s = Float.toString(1.001f); if (!s.equals("1.001")) { System.out.println ("Float.toString(1.001f) = " + s); throw new Exception("Float.toString(\"1.001\") != \"1.001\""); } s = Float.toString(123.123f); if (!s.equals("123.123")) { System.out.println("Float.toString(123.123) = " + s); throw new Exception("Float.toString(\"123.123\" != \"123.123\""); } s = Float.toString(0.1f); if (!s.equals("0.1")) { System.out.println ("Float.toString(0.1f) = " + s); throw new Exception("Float.toString(\"0.1\") != \"0.1\""); } s = Float.toString(0.01f); if (!s.equals("0.01")) { System.out.println ("Float.toString(0.01f) = " + s); throw new Exception("Float.toString(\"0.01\") != \"0.01\""); } s = Float.toString(0.0001f); if (!s.equals("1.0E-4")) { System.out.println ("Float.toString(0.0001f) = " + s); throw new Exception("Float.toString(\"0.0001\") != \"1.0E-4\""); } // Test Double.toString s = Double.toString(0.001); if (!s.equals("0.001")) { System.out.println ("Double.toString(0.001) = " + s); throw new Exception("Double.toString(\"0.001\") != \"0.001\""); } s = Double.toString(1.001); if (!s.equals("1.001")) { System.out.println ("Double.toString(1.001) = " + s); throw new Exception("Double.toString(\"1.001\") != \"1.001\""); } s = Double.toString(123.123); if (!s.equals("123.123")) { System.out.println("Double.toString(123.123) = " + s); throw new Exception("Double.toString(\"123.123\" != \"123.123\""); } s = Double.toString(0.1); if (!s.equals("0.1")) { System.out.println ("Double.toString(0.1) = " + s); throw new Exception("Double.toString(\"0.1\") != \"0.1\""); } s = Double.toString(0.01); if (!s.equals("0.01")) { System.out.println ("Double.toString(0.01) = " + s); throw new Exception("Double.toString(\"0.01\") != \"0.01\""); } s = Double.toString(0.0001); if (!s.equals("1.0E-4")) { System.out.println ("Double.toString(0.0001) = " + s); throw new Exception("Double.toString(\"0.0001\") != \"1.0E-4\""); } } }