Code example for FieldPosition

0
        if (pval < 0.0001){
            df = new DecimalFormat("0.0000E0", new DecimalFormatSymbols(Locale.US));
        }else{ 
            df = new DecimalFormat("0.0000", new DecimalFormatSymbols(Locale.US));
        } 
        String formattedNumber =  df.format(pval, new StringBuffer(), new FieldPosition(NumberFormat.INTEGER_FIELD)).toString();
        return formattedNumber;
    } 
 
    public static double roundDouble (double d, int places){
        double factor = Math.pow(10,places);
        return Math.rint(d*factor)/factor;
    } 
}