<BigInteger>
import java.math.*;
public class Main {
public static void main(String[] args) {
System.out.println("MAX Integer : " + Long.MAX_VALUE);
System.out.println("MIN Integer : " + Long.MIN_VALUE);
BigInteger bigVal1 = new BigInteger("100000000000000000000");
BigInteger bigVal2 = new BigInteger("-99999999999999999999");
BigInteger addResult = bigVal1.add(bigVal2);
BigInteger mulResult = bigVal1.multiply(bigVal2);
System.out.println("ADD : " + addResult);
System.out.println("MUL : " + mulResult);
}
}
<result>
MAX Integer : 9223372036854775807
MIN Integer : -9223372036854775808
ADD : 1
MUL : -9999999999999999999900000000000000000000
<BigDecimal>
import java.math.*;
public class Main {
public static void main(String[] args) {
BigDecimal e1 = new BigDecimal(1.6);
BigDecimal e2 = new BigDecimal(0.1);
System.out.println("ADD : " + e1.add(e2));
System.out.println("MUL : " + e1.multiply(e2));
}
}
<result>
ADD : 1.7000000000000000943689570931383059360086917877197265625
MUL : 0.1600000000000000177635683940025051398161724525855033823303533017413935457540219431393779814243316650390625
<BigDecimal>
import java.math.*;
public class Main {
public static void main(String[] args) {
BigDecimal e1 = new BigDecimal("1.6");
BigDecimal e2 = new BigDecimal("0.1");
System.out.println("ADD : " + e1.add(e2));
System.out.println("MUL : " + e1.multiply(e2));
}
}
<result>
ADD : 1.7
MUL : 0.16
'IT칼럼 > JAVA' 카테고리의 다른 글
isPalindrome (0) | 2019.03.08 |
---|---|
Comparable vs Comparator (0) | 2018.11.04 |
Priority Queue (0) | 2018.11.03 |
StringBuilder example (0) | 2018.11.03 |
StringTokenizer example (0) | 2018.11.03 |