Created
June 4, 2017 02:00
-
-
Save nattybear/6693ca4a3b9431737c7f9d5c914f704b to your computer and use it in GitHub Desktop.
C언어 소수 서식문자
This file contains hidden or 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 <stdio.h> | |
| int main() { | |
| float a = 0.123456f; | |
| // %f 서식문자는 고정 소수점 형식으로 출력한다. | |
| // 즉 보통 사람들이 소수점을 쓰듯이 표현된다. | |
| printf("%f\n", a); // 0.123456 | |
| // %e 서식문자는 부동 소수점 형식으로 출력한다. | |
| // 부동 소수점은 1.XXXXXX와 같이 적어주고 | |
| // 뒷부분에 e를 적어준 후 | |
| // 빼기를 적어주면 소수점을 왼쪽으로 옮기고 | |
| // 더하기가 적혀있다면 소수점을 오른쪽으로 옮긴다. | |
| // 아래 예제에서는 e 다음에 -01 이라고 적혀 있으므로 | |
| // 소수점을 왼쪽으로 한칸 옮긴 0.123456이 된다. | |
| printf("%e\n", a); // 1.234560e-01 | |
| // %g 서식문자는 | |
| // %f와 %e 서식문자 둘중에 짧은 것을 골라서 | |
| // 자동으로 출력해준다. | |
| printf("%g\n", a); // 0.123456 | |
| return 0; | |
| } |
Author
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
소수점을 표현하는 방법
소수점을 표현하는 방법에는 크게 아래 두가지가 있어
인터넷에서 한번쯤 검색해봐
C언어 공부는 아래 사이트를 추천