File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Java in General and the fly likes Trouble with double primitive type Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Customer Requirements for Developers this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Java » Java in General
Bookmark "Trouble with double primitive type" Watch "Trouble with double primitive type" New topic

Trouble with double primitive type

M Burke
Ranch Hand

Joined: Jun 25, 2004
Posts: 393
I have a double value that can get very large, and when it goes over 10 million, java starts storing it in scientific notation.

So if double = 9999999.00, it look to me in the debugger as 9999999.00

But when the double over 10000000.00 it looks like 1.00E7.

It is messing up my report formating. How can I get the number to not convert to scientific notation?
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
Typically, all double no matter their size are *stored* in scientific notation (okay, actually it's a variation that is given by some IEEE standard). I suspect you are worried more about how the double is *displayed* instead. You should be able to get some control over this by using NumberFormat. Take a look at the API docs (follow the link) for more information.


[ October 06, 2004: Message edited by: Layne Lund ]

Java API Documentation
The Java Tutorial
Nigel Browne
Ranch Hand

Joined: May 15, 2001
Posts: 673
Anoter option is to turn your double into a BigDecimal. For example
this will print the following:
This is a double :1.0E8
This is a BigDecimal :100000000
M Burke
Ranch Hand

Joined: Jun 25, 2004
Posts: 393
that worked great, thanks
I agree. Here's the link:
subject: Trouble with double primitive type
jQuery in Action, 3rd edition