• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

format a scientific notation double to a non scientific notation double  RSS feed

 
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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().)
 
Lisa Zapson
Ranch Hand
Posts: 50
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I appreciate you subtlety, I couldn�t agree more! I will rethink what I�m trying to do.

Thanks, Lisa
 
lowercase baba
Posts: 12628
50
Chrome Java Linux
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!!!
 
Greenhorn
Posts: 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
author
Posts: 3281
5
Eclipse IDE Java Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Alex,

Please post your question in a new thread, we try not to WakeTheZombies
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!