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!
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
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)
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With