> For the complete documentation index, see [llms.txt](https://heunnajo.gitbook.io/java/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://heunnajo.gitbook.io/java/java.lang-package-and-useful-class/math-class.md).

# Math class

Math class : Group of static method that are related math.

Round(반올림하다)\
\- round() : 소수점 아래 세 번째 자리에서 반올림. \
1\. 원래 값에 100을 곱한다. 90.7552 \* 100 -> 9075.52\
2\. 위의 결과에 Math.round()를 사용한다.  Math.round(9075.52) -> 9076\
3\. 위의 결과를 다시 100.0으로 나눈다.  9076 / . 00.0 -> 90.76, 9076 / 100 -> 90

* Math class Method

| Method                                                                                                                                                                                                                                                                                                                                        | Description                                                                                               | Example                                                                                                                                                                                                                                                                                                             |
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | --------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| <p>static <strong>double</strong> abs(<strong>double</strong> a)</p><p>static <strong>float</strong> abs(<strong>float</strong> a)</p><p>static <strong>int</strong> abs(<strong>int</strong> a)</p><p>static <strong>long</strong> abs(<strong>long</strong> a)</p>                                                                          | 주어진 값의 절대값을 반환한다.                                                                                         | <p>int i = Math.abs(-10);//10</p><p>double d = Math.abs(-10.0);//10.0</p>                                                                                                                                                                                                                                           |
| static double ceil(double a)                                                                                                                                                                                                                                                                                                                  | 주어진 값을 올림하여 반환한다. 양수든 음수든 더 큰 쪽으로!                                                                        | <p>double d = Math.ceil(10.1);//11.0<br>double d2 = Math.ceil(-10.1);//-10.0<br>double d3 = Math.ceil(10.000015);//11.0</p><p></p>                                                                                                                                                                                  |
| static double floor(double a)                                                                                                                                                                                                                                                                                                                 | 주어진 값을 버림하여 반환한다. 양수든 음수든 더 작은 쪽으로!                                                                       | <p>double d = Math.floor(10.8);//10.0</p><p>double d2 = Math.floor(-10.8);//-11.0</p>                                                                                                                                                                                                                               |
| <p>static double max(double a, double b)</p><p>static float max(float a, float b)</p><p>static double max(int a, int b)</p><p>static double max(long a, long b)</p><p></p><p>static double min(double a, double b)</p><p>static float min(float a, float b)</p><p>static double min(int a, int b)</p><p>static double min(long a, long b)</p> | 주어진 두 값을 비교하여 큰 쪽/작은 쪽을 반환한다.                                                                             | <p>double d = Math.max(9.5, 9.50001);//d = 9.50001</p><p>int i = Math.max(0,-1);//0</p><p></p><p>double d2 = Math.min(9.5, 9.50001);//9.5</p><p>int i = Math.min(0,-1);//-1</p>                                                                                                                                     |
| static double random()                                                                                                                                                                                                                                                                                                                        | 0.0\~1.0 범위의 임의의 double 값을 반환한다.(1.0은 불포함)                                                                | <p>double d = Math.random();</p><p>int i = (int)(Math.random()\*10)+1;</p><p></p><p>0.0 <= d < 1.0</p><p>1 <= i < 11</p>                                                                                                                                                                                            |
| static double rint(double a)                                                                                                                                                                                                                                                                                                                  | 주어진 double값과 가장 가까운 정수값을 double형으로 반환한다. 단, 두 정수의 정 가운데 있는 값(1.5, 2.5, 3.5 등)은 짝수를 반환한다.=>round보다 오차가 적다. | <p>double d = Math.rint(1.2);//1.0</p><p>double d2 = Math.rint(2.6);//3.0</p><p>double d3 = Math.rint(3.5);//4.0</p><p>double d4 = Math.rint(4.5);//4.0</p>                                                                                                                                                         |
| <p>static long round(double a)</p><p>static long round(float a)</p>                                                                                                                                                                                                                                                                           | <p>소수점 첫째자리에서 반올림한 정수값(long)을 반환한다. 두 정수의 정가운데 있는 값은 항상 큰 정수를 반환한다.</p><p>rint()의 결과와 비교</p>              | <p>long l = Math.round(1.2);//1</p><p>long l2 = Math.round(2.6);//3</p><p>long l3 = Math.round(3.5);//4</p><p>long l4 = Math.round(4.5);//5</p><p></p><p>double d = 90.7552;//90.7552</p><p>double d2 = Math.round(d\*100)/100.0;//90.76</p><p>//9075.52 / 100.0 = 90.7552</p><p>//Math.round(90.7552) = 90.76.</p> |

![round(), rint() result](https://513632279-files.gitbook.io/~/files/v0/b/gitbook-legacy-files/o/assets%2F-MHGT1oKZbTmlBrsOv_R%2F-MITPUpgWxNlOeGWzKN_%2F-MITRbfrU5dzHjAzHyIR%2Fimage.png?alt=media\&token=3177ae0c-eb78-4f9b-9c88-56d239bf3f29)
