Precision Example

import java.text.*;


public class PrettyTable {

  public static void main(String[] args) {
  
    System.out.println("Degrees Radians Grads");
    NumberFormat myFormat = NumberFormat.getInstance();
    myFormat.setMinimumIntegerDigits(3);
    myFormat.setMaximumFractionDigits(2);
    myFormat.setMinimumFractionDigits(2);
    for (double degrees = 0.0; degrees < 360.0; degrees++) {
      String radianString = myFormat.format(Math.PI * degrees / 180.0);
      String gradString = myFormat.format(400 * degrees / 360);
      String degreeString = myFormat.format(degrees);
      System.out.println(degreeString + "  " + radianString 
       + "  " + gradString);
    }
    
  }

}


Output:

300.00  005.23  333.33
301.00  005.25  334.44
302.00  005.27  335.55
303.00  005.28  336.66
304.00  005.30  337.77
305.00  005.32  338.88
306.00  005.34  340.00
307.00  005.35  341.11
308.00  005.37  342.22
309.00  005.39  343.33
310.00  005.41  344.44
311.00  005.42  345.55
312.00  005.44  346.66
313.00  005.46  347.77
314.00  005.48  348.88


Previous | Next | Top | Cafe con Leche

Copyright 2000 Elliotte Rusty Harold
elharo@metalab.unc.edu
Last Modified January 29, 2000