Here you can find the source of formatDouble(double val)
protected static String formatDouble(double val)
//package com.java2s; public class Main { protected static String formatDouble(double val) { String out = String.valueOf(val); if (out.length() > 5) { boolean round = false; if (round && out.charAt(5) != '.') if (Integer.parseInt(String.valueOf(out.charAt(5))) > 4) round = true;//from ww w . ja va2s. c om out = out.substring(0, 5); if (round && out.charAt(4) != '.') out = out.substring(0, 4) + String.valueOf(Integer.parseInt(String.valueOf(out.charAt(4))) + 1); else // trim off final decimal point out = out.substring(0, 4); } return out; } }