public static void main(String[] args) { double ff = 0.000000; System.out.println(SubStringLaLotude(ff)); } private static String getStringFormatIndex(String result, int formatIndex) { String strLanlot; strLanlot = String.format("%-" + formatIndex + "s", result).replace(" ", "0"); return strLanlot; } public static String SubStringLaLotude(Double number) { String strLanlot = "0.000000"; strLanlot = String.valueOf(number); // 获得第一个点的位置 int index = strLanlot.indexOf("."); // 根据点的位置,截取 字符串。得到结果 result String result = strLanlot.substring(index); if (result.length() < 7) { result = getStringFormatIndex(result, 7); } strLanlot = strLanlot.substring(0, index) + result.substring(0, 7); return strLanlot; }
保留小数点后6位数,以0补全
最新推荐文章于 2024-04-30 17:28:01 发布