Best way to Format a Double value to nth Decimal places in Java

Best way to Format a Double value to nth Decimal places in Java
------------------------------------------------------------------
public static double getDoubleValue(String value,int digit){
        if(value==null){
            value="0";
         }
        double i=0;
         try {
             DecimalFormat digitformat = new DecimalFormat("#.##");
             digitformat.setMaximumFractionDigits(digit);
            return Double.valueOf(digitformat.format(Double.parseDouble(value)));
           
        } catch (NumberFormatException numberFormatExp) {
            return i;   
        }
    }


Comments

Popular posts from this blog

Struts 2 : Warning :No configuration found for the specified action: 'Login.action' in namespace: '/'

Upload csv file at Google Cloud Storage using java

Read Images from a xlsx file using Apache POI