我怎么能转换String,如"12.34"一个double在Java中?
将Object转换为double并注意到这两种方法.我看到parseDouble从1.2开始就已经存在了.为什么添加此方法,如果它基本上与valueOf(s)功能相同?
在Java中将double转换为十六进制字符串相当简单.但是我该怎么做呢?我的代码在下面,我已经注意到NumberFormatException抛出的位置(大约2/3rds).
public class HexToDoubleTest {
public static void main( String args[] ) {
// This is the starting double value
double doubleInput = -9.156013e-002;
// Convert the starting value to the equivalent value in a long
long doubleAsLong = Double.doubleToRawLongBits( doubleInput );
// Convert the long to a String
String doubleAsString = Long.toHexString( doubleAsLong );
// Print the String
System.out.println( doubleAsString );
// Attempt to parse the string back as a long
// !!! This fails with a …Run Code Online (Sandbox Code Playgroud)