Round Number to n Decimal Place

2. Round Number to n Decimal Place

//here we used format() method to print the given decimal number to 3 decimal places
//The format string %.3f specifies to print the number to 3 decimal places.


//Round number to n decimal place
package com.company;

import java.util.Stack;

public class Main {

public static void main(String[] args) {

//dicimal number
double num= 5.873324;
//print number to 3 decimal places
System.out.format("%.5f",num);

}

}

Comments

Popular posts from this blog

the distance between two cities (in km is input through the keyboard. write a program to convert and print this distance in meter ,feet inches and centimeter.

CREATE UNIT CONVERTER APP

write a program to check whether a triangle is valid or not, when the threeangles of the triangle are entered through the keyboard. A triangle is valid if the sumof all the three angles is equal to 180 degrees