Math.floor() / Math.floorDiv()

2023. 4. 17. 22:16

💡 자바에서 내림연산을 하기 위한 Math.floor() 메서드 

double num = 3.8;
double result = Math.floor(num);
System.out.println(result); // 출력 결과: 3.0
  • double 형태의 숫자를 내림한 결과를 double 형태로 반환

 

💡 자바에서 내림연산을 하기 위한 Math.floorDiv() 메서드 

float num = 3.8f;
int result = Math.floorDiv((int) num, 1);
System.out.println(result); // 출력 결과: 3
  • float 타입의 값을 내림 연산하고 싶다면 'Math.floorDiv()' 사용
    ➡️ 매개변수로 받은 float 형태의 숫자를 내림한 결과를 int 형태로 반환

'Java > Method' 카테고리의 다른 글

str.replace(char oldChar, char newChar)  (0) 2023.04.22
Character.getNumericValue()  (0) 2023.04.22
Arrays.toString() / Arrays.deepToString()  (0) 2023.04.21
length / length()  (0) 2023.04.20
forDigit() 메서드  (0) 2023.04.17

BELATED ARTICLES

more