Java Double Number Format roundFormat(double d, int i)

Here you can find the source of roundFormat(double d, int i)

Description

round Format

License

Apache License

Declaration

public static String roundFormat(double d, int i) 

Method Source Code

//package com.java2s;
/*//from w ww. j  a va2s  . c om
 * Copyright 2014-2024 the https://github.com/xiaoxing598/itganhuo.
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * This project consists of JAVA private school online learning community group Friends co-creator [QQ group 329232140].
 * ????JAVA???????????????????[QQ?329232140];
 * See the list of IT dry technology sharing network [http://www.itganhuo.cn/teams].
 * ???????????IT???????[http://www.itganhuo.cn/teams];
 * The author does not guarantee the quality of the project and its stability, reliability, and security does not bear any responsibility.
 * ?????????????????????????????????????????.
 */

public class Main {

    public static String roundFormat(double d, int i) {
        String num = null;
        if (i == 1) {
            num = "0.0";
        }
        if (i == 2) {
            num = "0.00";
        }
        if (i == 3) {
            num = "0.000";
        }
        if (i == 4) {
            num = "0.0000";
        }
        if (i == 0) {
            num = "0";
        }
        java.text.DecimalFormat df = new java.text.DecimalFormat(num);
        return df.format(d);
    }
}

Related

  1. getFormattedValue(double argDoubleValue)
  2. getTwoDecimalByDecimalFormat(double number)
  3. getValidString(Double value, DecimalFormat formatter)
  4. isDoubleWhitFormat(String pValue)
  5. prettyDecimalFormat(double d, int numPlaces)
  6. shorten(double num)
  7. toDoubleFromHumanFormat(String doubleAsString)
  8. toString(double in, String format)
  9. toString(double[] arr, NumberFormat nf)