Java double type format to keep only two decimals

Description

Java double type format to keep only two decimals


import java.text.DecimalFormat;

public class Main {
    public static void main(String[] argv) throws Exception {
        double value = 98765.45678;
        System.out.println(doubleFormat(value));
    }//w  w  w .  j  av  a 2s. com

    private static DecimalFormat df = new DecimalFormat("#0.00");

    public static String doubleFormat(Double value) {
        return df.format(value);
    }
}



PreviousNext

Related