Java15 Math.round()
1183 단어 반올림Math.round나머지연산자Math.round
// Math.round()
// 실수를 소수첫째자리에서 반올림한 정수를 반환
long result = Math.round(4.52); //반올림되서 5
long result2 = Math.round(4.32); //반올림 안되니까 4
System.out.println(result);
System.out.println(result2);
double pi = 3.141592;
Math.round(pi*1000);
double shortPi = Math.round(pi*1000)/1000.0;
System.out.println(shortPi);
System.out.println(Math.round(pi*1000));
System.out.println(Math.round(pi*1000)/1000);
//인트나누기인트라서 소수점제외하고 나와서 3나옴
System.out.println(Math.round(pi*1000)/1000.0);
//소수점 나오게하고 싶으면 하나를 더블 바꾸면됨
/*
* Math.round(pi*1000)/1000.0
* Math.round(3.141592*1000)/1000.0
* Math.round(3141.592)/1000.0
* 3142/1000.0
* 3.142
*
* */
System.out.println("//////////////////////");
//3.141을 얻으려면?
System.out.println(pi*1000);
System.out.println((int)(pi*1000));
System.out.println((int)(pi*1000)/1000.0); //이렇게해야 3.141
System.out.println((int)(pi*1000)/1000); //인트나누기인트라서 3 나옴
//나머지 연산자 %
//1. 피연산자로 정수만 허용 2. 부호는 무시된다
System.out.println("////////////////////");
System.out.println(10%8);
System.out.println(10%-8);
Author And Source
이 문제에 관하여(Java15 Math.round()), 우리는 이곳에서 더 많은 자료를 발견하고 링크를 클릭하여 보았다 https://velog.io/@gogomango/Java15-Math.round-4s0iarpg저자 귀속: 원작자 정보가 원작자 URL에 포함되어 있으며 저작권은 원작자 소유입니다.
우수한 개발자 콘텐츠 발견에 전념 (Collection and Share based on the CC Protocol.)