Here you can find the source of formatDouble(Double in)
Parameter | Description |
---|---|
in | positive precision |
public static String formatDouble(Double in)
//package com.java2s; //License from project: Apache License import java.text.*; public class Main { /**//from w ww .j a va 2s.c om * convert a double into a String with a given precision * default double formatting is not very pretty * @param in non-null Double to convert * @param int positive precision * @return non-null formatted string */ public static String formatDouble(Double in, int precision) { return (formatDouble(in.doubleValue(), precision)); } /** * convert a double into a String with a given precision * default double formatting is not very pretty * @param in double to convert * @param int positive precision * @return non-null formatted string */ public static String formatDouble(double in, int precision) { NumberFormat nf = NumberFormat.getInstance(); nf.setMaximumFractionDigits(precision); return (nf.format(in)); } /** * convert a double into a String with a given precision * default double formatting is not very pretty * This version defaults precision to 2 * @param in non-null Double to convert * @param in positive precision * @return non-null formatted string */ public static String formatDouble(Double in) { return (formatDouble(in.doubleValue())); } /** * convert a double into a String with a given precision * default double formatting is not very pretty * This version defaults precision to 2 * @param in double to convert * @return non-null formatted string */ public static String formatDouble(double in) { return (formatDouble(in, 2)); } }