Here you can find the source of formatDoubleAsString(double num, int n)
public static String formatDoubleAsString(double num, int n)
//package com.java2s; //License from project: Open Source License public class Main { public static String formatDoubleAsString(double num, int n) { String ret = String.format("%." + n + "f", num).replace(',', '.'); if (ret.length() > 5) { ret = String.format("%5.2e", Double.parseDouble(ret)); }//from ww w . java 2s .c o m return ret; } }