001package edu.pdx.cs410J.tips;
002
003import java.math.BigDecimal;
004
005/**
006 * This program demonstrates that {@link BigDecimal}s provide
007 * arbitrary-precision decimal arithmetic.
008 *
009 * @see DoubleTrouble
010 *
011 * @author David Whitlock
012 * @version $Revision: 1.1 $
013 */
014public class BigDecimalDemo {
015
016  public static void main(String[] args) {
017    BigDecimal increment = new BigDecimal("0.10");
018    BigDecimal total = new BigDecimal("0.0");
019    for (int i = 0; i < 10; i++) {
020      System.out.println(total);
021      total = total.add(increment);
022    }
023    BigDecimal one = new BigDecimal("1.00");
024    System.out.println(total +
025                       (total.equals(one) ? "\nYes" : "\nNo?"));
026  }
027
028}