Reputation: 836
I have this String: 1303317717.65384 - It's a UNIX timestamp (1303317717) with milliseconds (65384).
How can I convert this to a float in Java? I am always getting 1.06172723E9 when giving it out, but I just want it to be 1303317717.65384.
Thanks!
Upvotes: 5
Views: 8241
Reputation: 3759
Floats in Java only have about six digits of precision. You need a double.
If it's in the form of a String, then you can use Double.parseDouble(String s)
.
Upvotes: 2
Reputation: 39217
It is not possible to display this with enough precision one within a float variable - you have to use a double.
Demo:
System.out.println(String.format("%f", Float.parseFloat("1303317717.65384")));
System.out.println(String.format("%f", Double.parseDouble("1303317717.65384")));
yields
1303317760.000000
1303317717.653840
Upvotes: 10