728x90
1 - 10 : float
1 - 11 : double
1 - 12 : decimal
10. float
< 특징 >
값의 범위 : 대략 -3.402823E38에서 3.402823E38까지. (-3.402823 곱하기 10의 38제곱 ~ 3.402823 곱하기 10의 38제곱)
정밀도 : 약 7자리 십진수
메모리 크기 : 4바이트
용도 : 과학적 계산, 그래픽 처리, 게임 개발 등에서 소수점 숫자를 다룰 때 사용됩니다.
float temperature = 36.6f;
float pi = 3.14f;
float largeNumber = 1.5e10f;
Console.WriteLine("현재 온도: " + temperature + "°C");
Console.WriteLine("원주율: " + pi);
Console.WriteLine("큰 숫자: " + largeNumber);
float increasedTemperature = temperature + 1.5f;
Console.WriteLine("온도 증가 후: " + increasedTemperature + "°C");
float preciseValue = 1.1234567f;
Console.WriteLine("정밀한 값: " + preciseValue);
11. double
< 특징 >
값의 범위: 대략 -1.79769313486232E308에서 1.79769313486232E308까지 (-1.79769313486232 곱하기 10의 308제곱 ~ 1.79769313486232 곱하기 10의 308제곱)
정밀도: 약 15-16자리 십진수
메모리 크기: 8바이트(64비트)
용도: 과학적 계산, 금융, 고정밀 수치 계산 등에서 소수점 숫자를 다룰 때 사용됩니다.
double gravitationalConstant = 9.80665;
double pi = 3.141592653589793;
double largeNumber = 1.7e+308;
Console.WriteLine("중력 가속도: " + gravitationalConstant + " m/s²");
Console.WriteLine("원주율: " + pi);
Console.WriteLine("큰 숫자: " + largeNumber);
double increasedValue = gravitationalConstant * 2;
Console.WriteLine("두 배의 중력 가속도: " + increasedValue + " m/s²");
double preciseValue = 1.12345678901234567;
Console.WriteLine("정밀한 값: " + preciseValue);
12. decimal
< 특징 >
값의 범위: 대략 ±1.0 × 10^-28에서 ±7.9 × 10^28까지
정밀도: 최대 28-29자리 십진수
메모리 크기: 16바이트(128비트)
용도: 금액 계산, 재무 데이터 처리 등에서 소수점 연산의 정확성이 중요한 경우에 사용됩니다.
decimal price = 19.99m;
decimal taxRate = 0.07m;
decimal totalPrice = price + (price * taxRate);
Console.WriteLine("가격: " + price + " 원");
Console.WriteLine("세율: " + taxRate * 100 + " %");
Console.WriteLine("총 가격: " + totalPrice + " 원");
decimal discount = 5.00m;
decimal finalPrice = totalPrice - discount;
Console.WriteLine("할인 후 최종 가격: " + finalPrice + " 원");
decimal preciseValue = 1.123456789123456789123456789m;
Console.WriteLine("정밀한 값: " + preciseValue);
728x90
'C# > 문법' 카테고리의 다른 글
C# 문법 15 -- 데이터 형식 정리 7 (0) | 2024.12.05 |
---|---|
C# 문법 14 -- 데이터 형식 정리 6 (0) | 2024.12.04 |
C# 문법 12 -- 데이터 형식 정리 4 (0) | 2024.12.02 |
C# 문법 11 -- 데이터 형식 정리 3 (0) | 2024.12.01 |
C# 문법 10 -- 데이터 형식 정리 2 (0) | 2024.11.30 |