Java Decimal Format adjustDoubleNumber(Double doubleNumber, int maxIntPart, int maxFloatPart)

Here you can find the source of adjustDoubleNumber(Double doubleNumber, int maxIntPart, int maxFloatPart)

Description

adjust Double Number

License

Open Source License

Declaration

public static Double adjustDoubleNumber(Double doubleNumber, int maxIntPart, int maxFloatPart) 

Method Source Code

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

import java.text.NumberFormat;
import java.text.ParseException;
import java.util.*;

public class Main {
    public static Double adjustDoubleNumber(Double doubleNumber, int maxIntPart, int maxFloatPart) {
        NumberFormat numberFormat = NumberFormat.getInstance(Locale.getDefault());
        numberFormat.setMaximumFractionDigits(maxFloatPart);
        numberFormat.setMaximumIntegerDigits(maxIntPart);
        numberFormat.setMinimumFractionDigits(maxFloatPart);
        try {// w w  w. j  a v a  2 s.  c om
            doubleNumber = numberFormat.parse(numberFormat.format(doubleNumber)).doubleValue();
        } catch (ParseException e) {
            new RuntimeException("The adjustDecimalNumber method haved an exception", e);
        }
        return doubleNumber;
    }
}

Related

  1. addDouble(Integer i, Double d)
  2. adjust(Double lng, Double lat, Double distance, Double angle)
  3. createMeanRmsString(double values[])
  4. decimal2percent(double decimal, int pos)
  5. decimal2string(BigDecimal arg, Locale loc)
  6. decimalConversation(double amount)