Convert String to Double while maintaining content

1

I need in Java to convert a String that has a binary value (Ex: "0111010") to a double . I tested:

String teste = "101010101";
double number = Double.parseDouble(teste);
System.out.println("The number is: " + number);

But the output is a totally different hexadecimal number. I need the output to be the same content as String . The double can even point somewhere, without problems, but needs to keep the same binary and in the same order.

    
asked by anonymous 04.05.2016 / 05:47

1 answer

2

I could not reproduce the problem. It worked for me. Of course, it appeared in scientific notation. If you wish to present in floating-point notation, you need to use the function that allows you to format the presentation:

System.out.printf("The number is: %f", number);

See running on ideone .

Formatter Documentation .

    
04.05.2016 / 05:59