Solution for Floating Point Infinite Loop

Home   »   Solution for Floating Point Infinite Loop

import java.math.BigDecimal;

public class FloatErrorUsingBigDecimal {
    public static void main(String[] args) {
        for (BigDecimal i = BigDecimal.valueOf(100);
             0 <= i.compareTo(BigDecimal.valueOf(0)); i = i.subtract(BigDecimal.valueOf(.1))) {
            System.out.println(i);
        }
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *