Saturday, February 28, 2009

source code float



package wclasses;

public class Samplefloat {
public static void main(String att[])
{

// constructors
Float f1= new Float(10.5);
Float fd=new Float(10.5d);
Float fs=new Float("10.5");

// wrapper to primitive
float pf1=f1.floatValue();
System.out.println(pf1);

//primitive to string
String s1=f1.toString();
String s2=Float.toString(10.57f);
System.out.println(s1);
System.out.println(s2);

//String to primitive
float pf2=Float.parseFloat(s2);
System.out.println(pf2);

//String to wrapper object
Float f2= new Float("10");
Float f3=Float.valueOf("100");
System.out.println(f2);
System.out.println(f3);

//wrapper to string
String s3=f3.toString();
}

}

output:
10.5
10.5
10.57
10.57
10.0
100.0



0 comments:

Post a Comment