Java Double Number to String doubleToString(double val, int maxFractionDigits)

Here you can find the source of doubleToString(double val, int maxFractionDigits)

Description

Converts a double to a string.

License

Apache License

Parameter

Parameter Description
val The double to convert
precision How many characters to include after '.'

Return

the double as a string.

Declaration

public static String doubleToString(double val, int maxFractionDigits) 

Method Source Code


//package com.java2s;
//License from project: Apache License 

import java.text.NumberFormat;

import java.util.Locale;

public class Main {
    /**//from   w  ww . j  a v  a2s  .  c o m
     * Converts a double to a string.
     * @param val The double to convert
     * @param precision How many characters to include after '.'
     * @return the double as a string.
     */
    public static String doubleToString(double val, int maxFractionDigits) {
        return doubleToString(val, maxFractionDigits, 0);
    }

    private static String doubleToString(double val, int maxFractionDigits, int minFractionDigits) {
        NumberFormat f = NumberFormat.getNumberInstance(Locale.US);
        f.setMaximumFractionDigits(maxFractionDigits);
        f.setMinimumFractionDigits(minFractionDigits);
        return f.format(val);
    }
}

Related

  1. doubleToString(double d, int df)
  2. doubleToString(double d, int precision)
  3. doubleToString(Double d, String format)
  4. doubleToString(double dnum)
  5. doubleToString(Double num)
  6. doubleToString(double value)
  7. doubleToString(double value, int afterDecimalPoint)
  8. doubleToString(double value, int fractionDigits)
  9. doubleToString(double value, int maximum, int minimum)