Java Fraction Format formatNum(double num, int numfracdigits)

Here you can find the source of formatNum(double num, int numfracdigits)

Description

format Num

License

Open Source License

Declaration

public static String formatNum(double num, int numfracdigits) 

Method Source Code


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

import java.text.NumberFormat;

public class Main {
    public static NumberFormat numberFormat = null;

    public static String formatNum(double num, int numfracdigits) {
        if (numberFormat == null) {
            // Cache the number format so that we don't have to get
            // info about local language etc. from the OS each time.
            numberFormat = NumberFormat.getInstance();
            // force to not include commas because we want the strings
            // to be parsable back into numeric values. - DRG
            numberFormat.setGroupingUsed(false);
        }//from w ww  .  j  a  v a  2  s  . c  om
        numberFormat.setMinimumFractionDigits(numfracdigits);
        numberFormat.setMaximumFractionDigits(numfracdigits);
        return numberFormat.format(num);
    }
}

Related

  1. formatManeyPattern(String pattern, Double amount)
  2. formatMetricsDecimal(double value)
  3. formatNoGrouping(double value)
  4. formatNormalDouble(double value)
  5. formatNum(double d)
  6. formatNum(float value)
  7. formatNumber(double decimal)
  8. formatNumber(double i)
  9. formatNumber(double num)