How to take two or three decimal point in JAVA


package SolveProblem;//package name....


import java.text.DecimalFormat;////import file for DecimalFormat

public class DecimalPoint {

    public static void main(String[] args) {
        double num1=345.98976876985;////This is any double value

        DecimalFormat df=new DecimalFormat(".####");//After four decimal point....

        //In java DecimalFormat is used for 2/3/4/.....decimal point
        //If you want to take your needed decimal format then use it....
       
        System.out.println("Ans is : "+df.format(num1));
    }

}

No comments:

Post a Comment