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

Read Images from a xlsx file using Apache POI

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

How to create mail message in FRC822 format