博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
浮点数取两位小数
阅读量:6632 次
发布时间:2019-06-25

本文共 953 字,大约阅读时间需要 3 分钟。

String str;		do{			Scanner scanner = new Scanner(System.in);			System.out.println("请输入年利率数字部分(如年利率为8.5%,则输入8.5即可.)");			str = scanner.nextLine();			float fff = (Float.parseFloat(str)*100)/360;			System.out.println("变形前:>>>>>"+fff+"");			System.out.println("万份日收益为:Math.round>>>>>"+(double)(Math.round(fff*100)/100.0)+"元");			System.out.println("万份日收益为:format>>>>>"+String.format("%.2f",fff));			DecimalFormat df = new DecimalFormat("#.##");			System.out.println("万份日收益为:DecimalFormat>>>>>"+Double.parseDouble(df.format(fff))+"    之前>>>>>"+df.format(fff));			System.out.println("万份日收益为:double>parseString>>>>>"+Double.parseDouble(String.format("%.2f", fff)));			BigDecimal bd = new BigDecimal(fff);			BigDecimal bd2 = bd.setScale(3, BigDecimal.ROUND_HALF_UP);			System.err.println("1111万份日收益为:BigDecimal>>>>>"+bd2.toString()+"   Double.parse>>>>>"+Double.parseDouble(bd2.toString()));		}while(true);

 

转载于:https://www.cnblogs.com/lowerCaseK/p/SetScale.html

你可能感兴趣的文章