Java:要浮动的毫秒时间戳字符串

Len*_*ann 4 java floating-point timestamp milliseconds

我有这个字符串:1303317717.65384 - 这是一个UNIX时间戳(1303317717),毫秒(65384).

如何在Java中将其转换为浮点数?放弃时我总是得到1.06172723E9,但我只想要它是1303317717.65384.

谢谢!

How*_*ard 9

在float变量中不可能以足够的精度显示它 - 你必须使用double.

演示:

System.out.println(String.format("%f", Float.parseFloat("1303317717.65384")));
System.out.println(String.format("%f", Double.parseDouble("1303317717.65384")));
Run Code Online (Sandbox Code Playgroud)

产量

1303317760.000000
1303317717.653840
Run Code Online (Sandbox Code Playgroud)