zoukankan      html  css  js  c++  java
  • mysql保留关键字 BigDecimal Double 四舍五入

    `desc`   需要加引号

    BigDecimal progress = new BigDecimal(0.444);
    progress=progress.setScale(2, BigDecimal.ROUND_HALF_UP);

    DecimalFormat df = new DecimalFormat("###0.00");
    df.setRoundingMode(RoundingMode.HALF_UP);
    df.format(new BigDecimal(amount));

    自动去多余的0

    public static String getTrimAmount(String amount){
         NumberFormat nf = NumberFormat.getInstance();

         nf.setGroupingUsed(false);  //不显示千位逗号
         return nf.format(new BigDecimal(amount));
    }

    //格式化

    DecimalFormat df=new DecimalFormat("0.00");
    double profitrate = 0.42;
    System.err.println(new Double(df.format(profitrate/100*10000/365).toString()));

    //百分比
    NumberFormat num = NumberFormat.getPercentInstance();
    num.setMaximumIntegerDigits(3);
    num.setMaximumFractionDigits(2);
    double csdn = 0.02086548;
    System.out.println(num.format(csdn));

  • 相关阅读:
    Windows下输入法全角符,半角符的切换
    hdu 2546 饭卡
    hdu 1712 ACboy needs your help
    hdu 3033 I love sneakers!
    hdu 1171 Big Event in HDU
    hdu 1114 Piggy-Bank
    HDU 1058 Humble Numbers
    hdu 1297
    hdu 2050
    hdu 2563
  • 原文地址:https://www.cnblogs.com/yangy608/p/4076557.html
Copyright © 2011-2022 走看看