This week's book giveaway is in the Agile and Other Processes forum.
We're giving away four copies of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java and have Dr. Raoul-Gabriel Urma & Richard Warburton on-line!
See this thread for details.
Win a flower (🌹) or copy of Real-World Software Development: A Project-Driven Guide to Fundamentals in Java (📚) this week in the Agile and Other Processes forum!
  • 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
  • Paul Clapham
  • Liutauras Vilda
  • Knute Snortum
  • Bear Bibeault
master stewards:
  • Devaka Cooray
  • Jeanne Boyarsky
  • Junilu Lacar
garden masters:
  • Ron McLeod
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • salvin francis
gardeners:
  • Tim Holloway
  • Piet Souris
  • Frits Walraven

double primitive in two forms

 
pioneer
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
when i print double sometimes it prints in exponential format sometimes in normal way.. what exactly is the rule behind this printing?
what is the largest number that will be printed in the normal way ?
 
pioneer
Posts: 132
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you give some examples of when you encounter this?
 
Java Cowboy
Posts: 16084
88
Android Scala IntelliJ IDE Spring Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you just print the number without specifying how it should be formatted, Java just uses the default formatting. If you don't want that, specify the formatting yourself.

If you are using Java 1.5 (or newer) you can use System.out.printf(...) with a format string to specify how you want your number formatted.

If you're using Java 1.4 (or older) you can use class java.text.DecimalFormat.

To answer your original question about the default formatting: you can find the answer in the API documentation of method java.lang.Double.toString(double), it explains in detail how the default formatting works.
 
Rizwan Mohammad
pioneer
Posts: 445
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks Jesper. Its clear now.
 
I wish to win the lottery. I wish for a lovely piece of pie. And I wish for a tiny ad:
Java file APIs (DOC, XLS, PDF, and many more)
https://products.aspose.com/total/java
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!