1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 | package pack; import java.math.BigDecimal; public class Test6bigdecimal { public static void main(String[] args) { // ์ปด์ double ์ฐ์ฐ์ฒ๋ฆฌ ์ค๋ฅ //double a = 1.5; //double b = 1.2; double a = 2.0; double b = 1.1; System.out.println(a + b); System.out.println(a - b); //๊ฒฐ๊ณผ๊ฐ .899999999999999๋ก ๋์ค๋ ๋ฐ ์ด๊ฒ์ ๋น๋จ JAVA๋ง์ ๋ฌธ์ ๋ ์๋๋ค System.out.println(); BigDecimal d1 = new BigDecimal("2.0"); BigDecimal d2 = new BigDecimal("1.1"); System.out.println(d1.subtract(d2)); //ํฐ ์ ์ ๊ฐ ์ฒ๋ฆฌ BigDecimal no1 = new BigDecimal("123456789123456789123456789"); BigDecimal no2 = new BigDecimal("123456789123456789123456780"); System.out.println(no1.add(no2)); System.out.println(no1.subtract(no2)); System.out.println(no1.multiply(no2)); System.out.println(no1.divide(no2, 4, BigDecimal.ROUND_UP)); } } | cs |
๋ฐ์ํ
'๐ป ํ๋ก๊ทธ๋๋ฐ > JAVA' ์นดํ ๊ณ ๋ฆฌ์ ๋ค๋ฅธ ๊ธ
2-8 ์กฐ๊ฑด ํ๋จ๋ฌธ switch (0) | 2016.06.26 |
---|---|
2-7 ์กฐ๊ฑดํ๋จ๋ฌธ if (0) | 2016.06.26 |
2-5 ํ๋ก๊ทธ๋จ๋์ค ํค๋ณด๋ ์ ๋ ฅ๊ฐ ๋ฐ๊ธฐ (0) | 2016.06.26 |
2-4 ๋ ผ๋ฆฌ์ฐ์ฐ์ (0) | 2016.06.26 |
2-3 ๊ด๊ณ ์ฐ์ฐ์, ๋ ผ๋ฆฌ ์ฐ์ฐ์, ๊ธฐํ (0) | 2016.06.26 |