parseDouble return scientific computing number

Q

Quick Function

if I use Double.parseDouble("0.0005"), it will return 5 E-4. How can I
get 0.0005? Thanks,

qq
 
M

Michael Borgwardt

Quick said:
if I use Double.parseDouble("0.0005"), it will return 5 E-4. How can I
get 0.0005?

You already *have* 0.0005. "0.0005" and "5e-4" are different representations
of the same abstract number, and parseDouble() returns the number, not any
particular representation (well, internally it's of course represented in
a different, third way, namely IEEE 754).

Your problem is not with parseDouble(), but with the way you're converting
the abstract number back into a String representation later on. If you want
to control that conversion, you have to use java.text.DecimalFormat.format()
instead of just doing something like System.out.println(number);
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top