| Author |
format a scientific notation double to a non scientific notation double
|
Lisa Zapson
Ranch Hand
Joined: Nov 22, 2004
Posts: 50
|
|
I'm trying to format a double in scientific notation to a double not in scientific notation. I tried using DecimalFormat to format the scientific notation double to a string. But, when I try to convert it back to a double I get the scientific notation back. 7.399999999999985E-5 To 0.00007 (When I create a new Double I get 7.0E-5 back). Any suggestions would be greatly appreciated. Thanks, Lisa
|
 |
Karan Rajan
Greenhorn
Joined: May 19, 2005
Posts: 12
|
|
Lisa, What did you try ? What was your output ? Here's what I tried : Take a look at the documentation and other examples on how to use the 'pattern' to suit your needs. [ January 17, 2007: Message edited by: Karan Rajan ]
|
 |
Lisa Zapson
Ranch Hand
Joined: Nov 22, 2004
Posts: 50
|
|
Hi Karan, I was also able to get a string of 0.00007. I now want to convert that string back into a double. I tried Double.valueOf(), Double.parseDouble() and New Double(). For each of these I get 7.0E-5. Thanks, Lisa
|
 |
Jim Yingst
Wanderer
Sheriff
Joined: Jan 30, 2000
Posts: 18670
|
|
The double itself has no concept of whether it's using scientific notation or not. That is only relevant when you try to convert it to a String. If you have two doubles: These are exactly equal in all ways. There is no difference at all. What you're asking for is impossible. If you want to convert either of these to a string that doesn't use scientific notation, you need to use the DecimalFormat, or similar methods. (JDK 5 has other methods which can help, e.g. String.format().)
|
"I'm not back." - Bill Harding, Twister
|
 |
Lisa Zapson
Ranch Hand
Joined: Nov 22, 2004
Posts: 50
|
|
I appreciate you subtlety, I couldn�t agree more! I will rethink what I�m trying to do. Thanks, Lisa
|
 |
fred rosenberger
lowercase baba
Bartender
Joined: Oct 02, 2003
Posts: 9939
|
|
|
If you can tell us exactly what you are trying to do, we can help. the more detail the better (within certain limits). code samples also help!!!
|
Never ascribe to malice that which can be adequately explained by stupidity.
|
 |
Alex Pri
Greenhorn
Joined: Nov 12, 2008
Posts: 1
|
|
Well. Got the same problem - get rid of scientific notation. But I don't want to lose any data, and I don't know in advance how many digits will it be. The only solution I see right now: If you can point me out how to get exactly 0.000075 with NumberFormat, please, do.
|
 |
Martijn Verburg
author
Bartender
Joined: Jun 24, 2003
Posts: 3268
|
|
Hi Alex, Please post your question in a new thread, we try not to WakeTheZombies
|
Cheers, Martijn - Blog,
Twitter, PCGen, Ikasan, My The Well-Grounded Java Developer book!,
My start-up.
|
 |
 |
|
|
subject: format a scientific notation double to a non scientific notation double
|
|
|