Re: Fortran-like number formatting



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
.



Relevant Pages

  • Re: Minus Zero
    ... "Precision as Formatted". ... with a General format when I realized that "precision as displayed" ... It might eliminate the need to use ROUND for the result of each cell. ... the result in A4 is now exactly zero. ...
    (microsoft.public.excel)
  • Re: Custom Format Limitation
    ... Excel, like nearly all software, uses for format called "Double Precision Floating Point" to store numbers. ... This is an industry-wide standard, kept by the Institute Of Electrical And Electronic Engineers -- it is in now way unique to Excel or to Microsoft product in general. ...
    (microsoft.public.excel.misc)
  • Re: Read Format
    ... That statement as is just skips a line, as you have no I/O ... array of double precision type. ... what your problem isn't - namely in the I/O format. ... DOUBLE PRECISION:: tol, sum_e2 ...
    (comp.lang.fortran)
  • Re: C code for converting IBM/370 floating point to IEEE 754?
    ... point format to IEEE 754 single precision format. ... the IBM format has greater range but less precision than the ... IEEE format. ...
    (comp.lang.c)
  • Re: 24bits conversion
    ... Invalid precision. ... fread with '*uint8' and typecastthe resulting byte stream to 'uint16'. ... format is "little-endian". ... while incount < len ...
    (comp.soft-sys.matlab)