• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Tim Cooke
  • Jeanne Boyarsky
  • Bear Bibeault
Sheriffs:
  • Knute Snortum
  • paul wheaton
  • Devaka Cooray
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Ron McLeod
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Tim Holloway
  • Carey Brown
  • salvin francis

Trouble with double primitive type

 
Ranch Hand
Posts: 421
  • 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?
 
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 ]
 
Ranch Hand
Posts: 704
  • 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: 421
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
that worked great, thanks
 
You totally ruined the moon. You're gonna hafta pay for that you know. This tiny ad agrees:
create, convert, edit or print DOC and DOCX in Java
https://products.aspose.com/words/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!