zoukankan      html  css  js  c++  java
  • 浮点数取两位小数

    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);
    
  • 相关阅读:
    javascript的自定义对象
    解决trim兼容性
    AJAX
    javascript中的默认对象
    js原始数据类型
    javascript的内置对象
    空判断啊
    javascript的继承
    html如何设置P的高度为零?
    asp.net 生成静态页 自动分页
  • 原文地址:https://www.cnblogs.com/lowerCaseK/p/SetScale.html
Copyright © 2011-2022 走看看