• 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 Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Displaying large doubles without scientific notation

 
Ranch Hand
Posts: 44
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
author
Posts: 23956
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Master Rancher
Posts: 4921
74
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I would probably try a DecimalFormat instead.
 
Henry Wong
author
Posts: 23956
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

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
 
Eliminate 95% of the weeds in your lawn by mowing 3 inches or higher. Then plant tiny ads:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic