How to convert float in round int.




 Here   an example of  simple  math  to process  the  a  input float number
 Input  any   float  number  through  command  line  and convert  it   in  round  
figure  using   Java. This  is vary  simple  but  useful  in scientific calculation.



import   java.util.*;
public class RoundIntegerJavaCode  {

public static void main(String[] args) {
// TODO Auto-generated method stub

Scanner reader = new Scanner(System.in); 
System.out.println("Enter a number: ");

                 float n =(float) reader.nextFloat();


 float   f = n;

  int  ir=(int)f;

     float  i= (int) (f%10) ;
     float fr=f-i;
     
     System.out.println(" int value" +i);
     System.out.println(" Float diffrence valule" +fr);
   
     if (fr>.5){
    
      System.out.println( "Round value of enter float"+ir+1);
     }
     else{
    
      System.out.println("Round value of enter float"+ir);
     }


}

}

Program Output:
Enter a number:
4.7
 int value4.0
 Float diffrence valule0.6999998
Round value of enter float::5
How to convert float in round int. How to convert float in round int. Reviewed by Mukesh Jha on 9:25 AM Rating: 5

No comments:

Add your comment

All Right Reserved To Mukesh Jha.. Theme images by Jason Morrow. Powered by Blogger.