// int, float, String type casting in java
public class Castingdatatypes
{
public int a=10;
public float b=10;
public String b1="11";
public float d1=1.1f;
public int e1=13;
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Castingdatatypes obj1= new Castingdatatypes();
obj1.casting();
}
public void casting()
{
float c;
int d;
float e;
//parseInt is a method for String conversions
c=Float.parseFloat(b1); // b1 is a String, we are converting it to float, nothing but
d=Integer.parseInt(b1); //String to int conversion
//e=(Integer)c;
e = (float)d1; //cannot convert from float to int. But this is float to float conversion
d1=(int)e1; //convert from int to float, is possible and now being converted.
//c= Float.parseFloat(b1); (b1);
System.out.println(c); //this outputs the float(String b1)
System.out.println(d); //this outputs the Int(String b1)
System.out.println(e); //this outputs the Int(float d1)
System.out.println(d1);//this outputs the float(int d1)
}
}
public class Castingdatatypes
{
public int a=10;
public float b=10;
public String b1="11";
public float d1=1.1f;
public int e1=13;
/**
* @param args
*/
public static void main(String[] args) {
// TODO Auto-generated method stub
Castingdatatypes obj1= new Castingdatatypes();
obj1.casting();
}
public void casting()
{
float c;
int d;
float e;
//parseInt is a method for String conversions
c=Float.parseFloat(b1); // b1 is a String, we are converting it to float, nothing but
d=Integer.parseInt(b1); //String to int conversion
//e=(Integer)c;
e = (float)d1; //cannot convert from float to int. But this is float to float conversion
d1=(int)e1; //convert from int to float, is possible and now being converted.
//c= Float.parseFloat(b1); (b1);
System.out.println(c); //this outputs the float(String b1)
System.out.println(d); //this outputs the Int(String b1)
System.out.println(e); //this outputs the Int(float d1)
System.out.println(d1);//this outputs the float(int d1)
}
}
This comment has been removed by the author.
ReplyDeleteWhen you read data from excel using POI package methods, one should know what type of data that excel cell has. This is because we use getStringcelldata or getNumericcelldata fuctions to read data. If you do not know what type of data the cell has how will you know which method needs to be used. So on the cell use .cellType method this will return String, Integer, float etc. So accordingly use get... method to retrieve data.
ReplyDelete