File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes Displaying large doubles without scientific notation Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Reply Bookmark "Displaying large doubles without scientific notation" Watch "Displaying large doubles without scientific notation" New topic
Author

Displaying large doubles without scientific notation

Jeremy Medford
Ranch Hand

Joined: Jan 16, 2007
Posts: 44
Can anyone share with me how to display very large doubles that would normally have no fractional part, but always display with scientific notation by default?

Basically, I want to see the number without Scientific Notation.

Thank you.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16684
    
  19

Originally posted by Jeremy Medford:
Can anyone share with me how to display very large doubles that would normally have no fractional part, but always display with scientific notation by default?

Basically, I want to see the number without Scientific Notation.

Thank you.


Well, you can take the double, load it into a BigDecimal, convert that BigDecimal to a BigInteger, then convert that to a string for printing. However, you have to be careful, doubles are not very precise, so you may get errors loading it into a BigDecimal.

If you have the original number in Scientific Notation as a string, then it should work perfectly. Just load that string into a BigDecimal, convert to BigInteger, and then to a string.


Now... having said this... This can probably be done without the BigInteger, by using scaling instead, so if someone knows how, I would appreciate if you share it.

Henry


Books: Java Threads, 3rd Edition, Jini in a Nutshell, and Java Gems (contributor)
Mike Simmons
Ranch Hand

Joined: Mar 05, 2008
Posts: 2778
    
    2
I would probably try a DecimalFormat instead.
Henry Wong
author
Sheriff

Joined: Sep 28, 2004
Posts: 16684
    
  19

Originally posted by Mike Simmons:
I would probably try a DecimalFormat instead.


Good point. I always use DecimalFormat to format the decimal side, and totally forgot it can do this...

Henry
 
I agree. Here's the link: http://zeroturnaround.com/jrebel - it saves me about five hours per week
 
subject: Displaying large doubles without scientific notation
 
Similar Threads
convert String->double->String
Changing number format to NOT do Scientific Notation....ever...
multiplying large "negative exponents"?
Increase the range of Double
converting bigdecimal