it leader

c# 변수의 형변환 ( Type Convertion)



  • 실수, 정수의 문자변환

int a =  3;

string str = a.ToString();


flaot b = 3.0f;

string str = b.ToString();



  • 정수 -> 실수 변환

int -> float 


int a = 3;


float b = (float)a;



  • 실수 -> 정수 변환

float a = 3.0f;

int b = (int)a;


double c = 123.45;


int d = (int)c;




  • 문자열 -> 실수, 정수 변환

string e = "123;

string f = "123.456";


int g = int.Parse(e);

float h = float.Parse(f);


또는


int g = Convert.ToInt32(e);

float h = Convert.ToSingle(h);







profile

it leader

@dev__pixui

포스팅이 좋았다면 "좋아요❤️" 또는 "구독👍🏻" 해주세요!