Created
February 27, 2024 02:40
-
-
Save bluesid/2a28a4bfbb07e395520012d25b9749c8 to your computer and use it in GitHub Desktop.
#Java #BigDecimal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
BigDecimal a = new BigDecimal("0.4"); | |
BigDecimal b = new BigDecimal("0.40"); | |
// 객체의 레퍼런스 주소에 대한 비교 연산자, 무의식적으로 값의 비교를 위해 사용하면 오동작 | |
// false | |
a == b; | |
// 값의 비교를 위해 사용, 소수점 맨 끝의 0까지 완전히 값이 동일해야 true 반환 | |
// false | |
a.equals(b); | |
// 값의 비교를 위해 사용, 소수점 맨 끝의 0을 무시하고 값이 동일하면 0, 적으면 -1, 많으면 1을 반환 | |
// 0 | |
a.compareTo(b); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment