Calculating PI with BigDecimal
问题 This is my first time using a BigDecimal and I am having some troubles with it. Here is my code: import java.math.BigDecimal; public class Test { public static void main(String[] args) { BigDecimal pi = new BigDecimal(4); boolean plus = false; for (int i = 3; i < 1000000; i += 2) { if (plus) { pi.add(new BigDecimal(4).divide(new BigDecimal(i), 2, BigDecimal.ROUND_HALF_UP)); } else { pi.subtract(new BigDecimal(4).divide(new BigDecimal(i), 2, BigDecimal.ROUND_HALF_UP)); } plus = !plus; } System