The following examples shows you how to convert data between float and other data types i.e., float to int , int to float , float to string etc....
Code
float to int :
float f = 1.6f;
int a = (int)f;//but here point value will be lost due to downcasting
System.out.println(a);
float to String :
float f = 1.232f;
String str = Float.toString(f);
System.out.println(str);
String to float :
String str = "1.3534f";
float f = Float.parseFloat(str);
System.out.println(f);
0 comments:
Post a Comment