Re: Fortran-like number formatting
- From: Roedy Green <see_website@xxxxxxxxxxxxxxxxxxxx>
- Date: Fri, 25 Apr 2008 10:11:29 GMT
On 25 Apr 2008 02:30:39 GMT, ram@xxxxxxxxxxxxxxxxxx (Stefan Ram)
wrote, quoted or indirectly quoted someone who said :
»After rounding for the precision, the formatting of the
resulting magnitude m depends on its value.
If m is greater than or equal to 10^-4 but less than
10^precision then it is represented in decimal format.
If m is less than 10^-4 or greater than or equal to
10^precision, then it is represented in computerized
scientific notation.
The total number of significant digits in m is equal to
the precision. If the precision is not specified, then the
default value is 6. If the pr
here are some sample uses
// Use of G format:
// %[flags][min width of field].[number of significant digits of
precision (not # of decimal places)]g
System.out.printf( "value is %4.3g\n", 1.4d );
// prints value is 1.40
System.out.printf( "value is %4.3g\n", 1.456d );
// prints value is 1.46
System.out.printf( "value is %4.3g\n", 145.0d );
// prints value is _145
System.out.printf( "value is %8.4g\n", 1.5d );
// prints value is ___1.500
System.out.printf( "value is %4.4g\n", 1.5E-6 );
// prints value is 1.500e-06
System.out.printf( "value is %,8.6g\n", 12345.0d );
// prints value is 12,345.0
I congratulate whomever designed it. It is considerably more useful
than the old FORTRAN G format it derives from.
--
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com
.
- References:
- Fortran-like number formatting
- From: Roedy Green
- Fortran-like number formatting
- Prev by Date: tomcat plugin question
- Next by Date: Automated teller machine help please
- Previous by thread: Fortran-like number formatting
- Next by thread: tomcat plugin question
- Index(es):
Relevant Pages
|