Search This Blog

Friday, 12 December 2014

int to float conversation and float to int conversation

Conversation from int to float and float to int is so easy. Java provide below method for conversation.



 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
public static void main(String args[]) {

  /**
   * integer to float conversation
   */
  int i=123;
  float f=(float)i;
  System.out.println("Float variable="+f);

  /**
   * float to integer conversation
   */
  float ff=123.665f;
  int ii=(int)Math.round(ff);
  System.out.println("Intger varibale="+ii);
 }
OutPut
Float variable=123.0
Intger varibale=124



No comments:

Post a Comment