/* 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. */ options binary -- use primitive arithmetic if possible import com.ibm.math -- import BigDecimal and MathContext f=float 9 -- binary floating point variable d=BigDecimal(9) -- decimal floating point variable def=MathContext.DEFAULT -- standard arithmetic context loop for 10 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(String(char[10-s.length])).replace('\0', ' ') System.out.println(s String.valueof(f)) end