Java Decimal Format trim(int degree, double d)

Here you can find the source of trim(int degree, double d)

Description

trim

License

Open Source License

Declaration

public static double trim(int degree, double d) 

Method Source Code


//package com.java2s;
//License from project: Open Source License 

import java.text.DecimalFormat;

public class Main {
    public static double trim(int degree, double d) {
        String format = "#.#";
        for (int i = 1; i < degree; i++) {
            format = format + "#";
        }//from   w w  w  . j a  va2  s .  c o  m
        DecimalFormat twoDForm = new DecimalFormat(format);
        return Double.valueOf(twoDForm.format(d)).doubleValue();
    }
}

Related

  1. toString(final Double value)
  2. toString(final double value, final int maxDecimalPlaces)
  3. toStringForHumans(double doubleToConvert)
  4. toStringNoDigits(double[] v)
  5. toStringScientific(double x)
  6. trim(int level, double value)
  7. trim2Decimals(Double value)
  8. truncate(double d)