File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Java in General and the fly likes format a scientific notation double to a non scientific notation double Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "format a scientific notation double to a non scientific notation double" Watch "format a scientific notation double to a non scientific notation double" New topic
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: 18671
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: 11444
    
  16

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!!!


There are only two hard things in computer science: cache invalidation, naming things, and off-by-one errors
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: 3274
    
    5

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: format a scientific notation double to a non scientific notation double