그래오늘은이거야

float 소수점 자르기 함수 본문

세상 개발/IOS(Objective-c)

float 소수점 자르기 함수

jinhongstar 2017. 1. 17. 14:55
728x90
반응형



소수점을 반올림하는 방법 입니다.

float myFloat = 3.333


소수점(.) 이후로 넘어가면 무조건 반올림을 합니다.


// for nearest integer rounded up (3.333 -> 4):

int result = (int)ceilf(myFloat );


소수점(.5) 이후로 넘어가면 무조건 반올림을 합니다.


// for nearest integer (3.4999 -> 3, 3.5 -> 4):

int result = (int)roundf(myFloat );


소수점(.) 이후로 넘어가도 반올림 하지 않습니다.


// for nearest integer rounded down (3.999 -> 3):

int result = (int)floor(myFloat);


// For just an integer value (for which you don't care about accuracy) 

int result = (int)myFloat;




my friend is stackoverflow


http://stackoverflow.com/questions/8785468/convert-float-to-int-in-objective-c

반응형
Comments