Last active
April 18, 2020 09:44
-
-
Save fpdjsns/83c1b2d3f157f68a1c7687948477b400 to your computer and use it in GitHub Desktop.
실수 출력(정수 부분, 반올림, 올림, 내림)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include<iostream> | |
using namespace std; | |
int main() | |
{ | |
float ans, temp; | |
ans = 4.7777; | |
temp = ans; | |
printf("원래 수 : %f\n", ans); | |
//정수부분 출력 | |
printf("정수부분 : %d\n", (int)temp); | |
//소수점 넷 째 자리 반올림 | |
printf("반올림 : %0.3f\n", temp); | |
temp = temp + 0.0005; | |
temp = (int)(temp * 1000); | |
temp = temp / 1000; | |
printf("반올림2 : %f\n", temp); | |
temp = ans; | |
//소수점 넷 째 자리 올림 | |
temp = temp + 0.0009; | |
temp = (int)(temp * 1000); | |
temp = temp / 1000; | |
printf("올림 : %f\n", temp); | |
temp = ans; | |
temp = temp * 1000; | |
temp = ceil(temp);//소수점 올림 | |
temp = temp / 1000; | |
printf("올림2 : %f\n", temp); | |
temp = ans; | |
//소수점 넷 째 자리 버리기 | |
temp = (int)(temp * 1000); | |
temp = temp / 1000; | |
printf("내림 : %f\n", temp); | |
temp = ans; | |
temp = temp * 1000; | |
temp = floor(temp); //소수점 이하 버림 | |
temp = temp / 1000; | |
printf("내림2 : %f\n", temp); | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
ㅠㅠ너무너무 감사합니다!!! 몇 시간 뒤져서 공부해도 명확한 답은 안나왔는데ㅠㅠㅠㅠ
해결 됐습니다!!!!!