File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "Float" Watch "Float" New topic


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.
Dirk Schreckmann

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

Good Luck.
Jim Yingst

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
I agree. Here's the link:
subject: Float
It's not a secret anymore!