/* 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 { 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)); } } }