/*
 * @(#)src/demo/bigdecimal/decdemo.java, math, ds1411, 20030828 1.7.2.1
 * ===========================================================================
 * Licensed Materials - Property of IBM
 * "Restricted Materials of IBM"
 *
 * IBM SDK, Java(tm) 2 Technology Edition, v1.4.1
 * (C) Copyright IBM Corp. 1998, 2003. All Rights Reserved
 * ===========================================================================
 */

/* 
 * Demonstration program showing use of the enhanced BigDecimal class.   
 *                                                                       
 * This shows the results of repeatedly dividing by ten, using:          
 *   BigDecimal (decimal floating point)                                 
 *   float      (binary floating point)                                  
 * datatypes.                                                            
 */

import com.ibm.math.*;   // import BigDecimal and MathContext

public class decdemo
 {
 
    static final String copyr = 
        "Licensed Materials - Property of IBM\n" +
        "IBM SDK, Java(tm) 2 Technology Edition, v1.4.1\n" +
        "(C) Copyright IBM Corp. 1998, 2003. All Rights Reserved\n" +
        "\n" +
        "US Government Users Restricted Rights - Use, duplication or disclosure\n" +
	"restricted by GSA ADP Schedule Contract with IBM Corp.\n" ;
 
  public static void main(String args[])
   {
    String        s;                    // work variable
    float         f=9;                  // binary floating point variable
    BigDecimal    d=new BigDecimal(9);  // decimal floating point variable
    MathContext def=MathContext.DEFAULT;// standard arithmetic context

    for (int i=0; i<10; i++)
     {
      d=d.divide(BigDecimal.TEN, def);  // divide using decimal floating point
      f=f/10;                           // divide using binary floating point

      // pad the first result with blanks for display, then display both
      s=d.toString();
      s=s.concat(new String(new char[10-s.length()])).replace('\000',' ');
      System.out.println(s+" "+String.valueOf(f));
     }
   }
 }

