zoukankan      html  css  js  c++  java
  • java中保留几位小数


    public class NumUtils {

    /**
    * 保留两位小数
    *
    * @param d
    * @return
    */
    public static String get2Wei(double d) {
    java.text.DecimalFormat df = new java.text.DecimalFormat("#.##");
    return df.format(d);
    }

    /**
    * 保留两位小数
    *
    * @param d
    * @return
    */
    public static String get2Wei(Float d) {
    if (d == null)
    return "0";
    java.text.DecimalFormat df = new java.text.DecimalFormat("#.##");
    return df.format(d);
    }

    /**
    * 保留0位小数
    *
    * @param d
    * @return
    */
    public static String get0Wei(double d) {
    java.text.DecimalFormat df = new java.text.DecimalFormat("#");
    return df.format(d);
    }

    /**
    * 保留0位小数
    *
    * @param d
    * @return
    */
    public static String get0Wei(Float d) {
    if (d == null)
    return "0";
    java.text.DecimalFormat df = new java.text.DecimalFormat("#");
    return df.format(d);
    }
    }
  • 相关阅读:
    golang单例模式
    PHP打开并修改文件
    关于文件服设计的一些想法
    Api
    golang Iterate through the fields of a struct in Go
    zookeeper note
    centos 6 install protoc
    todo
    linux route
    build http_load
  • 原文地址:https://www.cnblogs.com/minghualiyan/p/5146033.html
Copyright © 2011-2022 走看看