jQuery in Action, 3rd edition
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
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: 397
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: 397
that worked great, thanks
I agree. Here's the link: http://aspose.com/file-tools
subject: Trouble with double primitive type
It's not a secret anymore!