DecimalUtils { public static String savePoint(double d, int point) { return String.format("%.".concat(point + "f"), d); } private  DecimalUtils(); static int convert2Hex(int n); static BigInteger double2BigInt(double d); static String saveTwoPoint(double d); static String savePoint(double d, int point); static byte[] byteBuffer2byteArray(ByteBuffer bb); static ByteBuffer byteArray2byteBuffer(byte[] ba);  }
@Test public void savePointTest() { assertEquals("0.23", DecimalUtils.saveTwoPoint(0.23456d)); assertEquals("1.23", DecimalUtils.saveTwoPoint(1.23456d)); assertEquals("11.23", DecimalUtils.saveTwoPoint(11.23456d)); assertEquals("1.23", DecimalUtils.saveTwoPoint(01.23456d)); assertEquals("10.23", DecimalUtils.saveTwoPoint(010.23456d)); assertEquals("10", DecimalUtils.savePoint(010.23456d, 0)); assertEquals("10.2", DecimalUtils.savePoint(010.23456d, 1)); assertEquals("10.2345600000", DecimalUtils.savePoint(010.23456d, 10)); }