HOWTO · Csharp
C#에서 Int를 Float로 변환
이 가이드는 C#에서 int를 float로 변환하는 방법을 알려줍니다. 그것은 단순히 캐스팅하여 수행할 수 있습니다.
이 페이지의 내용
이 가이드는 C#에서 int를 float로 변환하는 방법을 알려줍니다. 그것은 단순히 캐스팅하여 수행할 수 있습니다.
typecasting 방법을 사용하여 int를 float 또는 decimal로 쉽게 변환할 수 있습니다. 한 번 보자.
C#에서 Int를 Float로 변환
유형 캐스팅을 사용하여 int를 float로 변환할 수 있습니다. int 변수 뒤에 (float)를 작성합니다.
예를 들어 int 변수가 temp_int인 경우 내부 값을 float 값으로 변환하려면 (float)temp_int를 작성하기만 하면 됩니다. 다음 코드를 살펴보십시오.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace Int_to_Float {
class Program {
static void Main(string[] args) {
// using type cast we can convert INT TO FLOAT OR DECIMAL...........
int temp_int = 1;
float temp_float = (float)temp_int;
decimal temp_decimal = 3;
float temp_float_decimal = (float)temp_decimal;
Console.WriteLine("INT TO FLOAT= " + temp_float);
Console.WriteLine("FLOAT TO DECIMAL= " + temp_float_decimal);
Console.ReadKey();
}
}
}
코드의 출력은 아래와 같습니다.
output:
INT TO FLOAT= 1
FLOAT TO DECIMAL= 3