BigDecimal 객체 생성 방법, 비교

객체를 생성할 때 실수가 아닌 String 형태 혹은 valueOf()를 사용하고 비교할 때는 compareTo()를 사용한다.

import java.math.BigDecimal;
public class Example {
    public static void main(String[] args) {
        BigDecimal val1 = BigDecimal.valueOf(1.234);
        BigDecimal val2 = new BigDecimal("1.234");

        System.out.println(val1.compareTo(val2) == 0);
    }
}

Boolean 객체의 사용법

인스턴스화하지 않고 static 필드인 TURE, FALSE를 사용한다.

public class BooleanExample {
    public static void main(String[] args) {
        // Boolean bool = new Boolean(ture);
        // Boolean bool2  = Boolean.valueOf(false);

        Boolean bool = Boolean.TRUE;
        Boolean bool2 = Boolean.FALSE;
     }
}

+ Recent posts