Here you can find the source of doubleToString(double val, int maxFractionDigits)
Parameter | Description |
---|---|
val | The double to convert |
precision | How many characters to include after '.' |
public static String doubleToString(double val, int maxFractionDigits)
//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); } }