1. 程式人生 > >floor函式與ceil函式的用法

floor函式與ceil函式的用法

loor(x)  is the largest integer not greater than x , 也就是,floor(x) 返回的是小於等於x的所有整數中最大的整數,簡單的說,就是去掉x的小數部分的整數

ceil(x)  is the smallest integer not less than x,也就是,ceil(x) 返回的是大於等於x的所有整數中最小的整數,簡單的說,就是如果x是整數,則返回該數,如果x不是整數,則不管小數部分是多少,都進一位然後返回。

例如:

floor(3.2)= 3;

ceil(3.2)= 4;

floor(4)= 4;

ceil(4)= 4