It's not a secret anymore!
The moose likes Java in General and the fly likes decimal - avoid scientific notation Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "decimal - avoid scientific notation" Watch "decimal - avoid scientific notation" New topic
Author

decimal - avoid scientific notation

Vicky Mohan
Ranch Hand

Joined: Oct 14, 2004
Posts: 130
I am trying to convert a String to Double. For a very small number like 0.0008, it is displayed in scientific notation. But i would like to want it displayed normally as 0.0008 ( for my example)

What can i do get this accomplished ?

Sample Code attached ..

--------------------------------------------------------------------------

public static void main(String[] args) {
String testDouble = “0.0008”;
Double returnDouble = new Double(returnValue);
System.out.println(" returnDouble " + returnDouble );
}

returnDouble 8.0E-4


Any help will be appreciated..
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 56233
    
  13

Please read this.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16696
    
  19

There is *no* such a thing as a format in a double. A double is just a value -- it doesn't hold the concept of notation. What is happening is that the double is formatted when it is printed. So, you can use printf() instead, which allows you to format the double (during printing). Or you can use the DecimalFormat class, which will format it back to a string so you can print it.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: decimal - avoid scientific notation
 
Similar Threads
Scientific notation
Convert String into double?
multiplying large "negative exponents"?
Trouble with double primitive type
format a scientific notation double to a non scientific notation double