Talk About Network



Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Java Help > Re: Fortran-lik...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 4 of 4 Topic 16019 of 16078
Post > Topic >>

Re: Fortran-like number formatting

by Roedy Green <see_website@[EMAIL PROTECTED] > Apr 25, 2008 at 10:11 AM

On 25 Apr 2008 02:30:39 GMT, ram@[EMAIL PROTECTED]
 (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




 4 Posts in Topic:
Fortran-like number formatting
Roedy Green <see_websi  2008-04-25 01:14:30 
Re: Fortran-like number formatting
ram@[EMAIL PROTECTED] (S  2008-04-25 01:45:22 
Re: Fortran-like number formatting
ram@[EMAIL PROTECTED] (S  2008-04-25 02:30:39 
Re: Fortran-like number formatting
Roedy Green <see_websi  2008-04-25 10:11:29 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Sat May 17 3:01:33 CDT 2008.