| 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
|
|
|
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
|
|
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)
|
 |
 |
|
|
subject: decimal - avoid scientific notation
|
|
|