Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Trouble with double primitive type

 
M Burke
Ranch Hand
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3061
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.

HTH

Layne
[ October 06, 2004: Message edited by: Layne Lund ]
 
Nigel Browne
Ranch Hand
Posts: 703
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 401
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that worked great, thanks
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic