Java 15 Math.round()

bitcogo·2022년 4월 8일
0

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);
profile
공부하고 기록하는 블로그

0개의 댓글