aspose file tools*
The moose likes Beginning Java and the fly likes Float Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Float" Watch "Float" New topic
Author

Float

Mahesh Mamani
Ranch Hand

Joined: Jun 25, 2001
Posts: 110
Hi All,
I want to get float value of a string, but for small values I get it in the form "6.0E-4". Can any1 help me in getting 0.0006 in Float value???

public class flt1{
public static void main(String kk[]){
String val = "0.0006";
Float resultflt = new Float(val);
System.out.println("Flt val is "+resultflt.floatValue());
}
}
Thanks in advance.
Mahesh
Dirk Schreckmann
Sheriff

Joined: Dec 10, 2001
Posts: 7023
Perhaps use DecimalFormat:

Good Luck.
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
Mahesh, try using the code you already wrote. The new Float(String) constructor already understands how to parse "6.0E-04" and the like. Incidentally you can also use Float.parseFloat(String) to get a float directly, without using a Float. Enjoy...


"I'm not back." - Bill Harding, Twister
Mahesh Mamani
Ranch Hand

Joined: Jun 25, 2001
Posts: 110
10x Dirk,
It worked
Mahesh
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Float