본문 바로가기

PHP/PHP함수

ceil(), floor(), round() 반올림 처리하는 함수들

ceil() 함수는 소수점 자리의 숫자를 무조건 올리는 함수이다.

ceil의 사전적의미 '<방에> 천장을 만들다'

처럼 무조건 소수점 자리를 올린다.

ceil(99.2) = 100

ceil(0.11111) = 1

ceil(5.9) = 6

ceil(-3.22) = -3

실수(float)을 정수(integer)로 만든다.


floor() 함수는 뜻 그대로 바닥으로 만든다.

소수점 아래를 무조건 무시

floor(3.6) = 3

floor(5.1) = 5

floor(-1.6) = -2 


round() 함수가 우리가 보통 알고 있는 반올림함수다.

round(3.4) : 3

round(5.6) : 6

round(9.5) :10

round(-2.5) : -3

round(-3.6) : -4

round(-5.4) : -5

'PHP > PHP함수' 카테고리의 다른 글

session_regenerate_id  (0) 2017.11.14
sprintf(), hash(), uniqid();  (0) 2017.11.13
$_SERVER 함수  (0) 2017.11.13
define() 초기설정값 셋팅  (1) 2017.11.12
글자수, 글자추출 strlen(), substr(), explode()  (0) 2014.10.30