Java Fraction Format format(double x, int max, int min)

Here you can find the source of format(double x, int max, int min)

Description

format

License

Open Source License

Declaration

public static double format(double x, int max, int min) 

Method Source Code

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

import java.text.NumberFormat;

public class Main {
    public static double format(double x, int max, int min) {
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMaximumFractionDigits(max);
        nf.setMinimumFractionDigits(min);

        try {/* ww  w .  j av  a2  s .c o  m*/
            Number number = nf.parse(nf.format(x));

            x = number.doubleValue();
        } catch (Exception e) {
            e.printStackTrace();
        }

        return x;
    }
}

Related

  1. format(double value)
  2. format(double value)
  3. format(double value, double unit)
  4. format(double value, int decimalPlace)
  5. format(double value, String formatString)
  6. format(final double d)
  7. format(final double number)
  8. format(final double value)
  9. format(final double value, final int decimalPlaces)