My app deals with mathematics and geometry, and it will often have to display floating point values. As you may know, floats often have gunk in their least significant digits after a few calculations so it is typically a bad idea to show them in all their glory (4.5000000000000000000003 or 3.294727893640192837562934), because your interface will end up being unreadable and intimidating. Simply rounding them to an arbitrary number of decimal places is better, but not ideal as it tends to sometimes remove information users do care about.
Does anyone know of a good formatting algorithm that displays floating point numbers in sufficient accuracy and sufficient readability for nearly all cases? I'm interested in figuring out when to round to how many digits, when to use scientific notation etc. etc.