Objective-C拓展了C,自然很多用法是和C一致的.比如浮点数转化成整数,就有以下四种情况. 1.简单粗暴,直接转化 float f = 1.5; int a; a = (int)f; NSLog("a = %d",a); 输出结果是1.(int)是强制类型转化,丢弃浮点数的小数部分. 2.高斯函数,向下取整 float f = 1.6; int a; a = floor(f); NSLog("a = %d",a); 输出结果是1.floor()方法是向下取整
SELECT round(52.45, 0) AS round4, round(52.54, 0) AS round5, round(52.45, 1) AS round41, round(52.54, 1) AS round51, floor(52.4) AS floor4, floor(52.5) AS floor5, ceiling(52.4) AS ceiling4, ceiling(52.5) AS ceiling5 round是四舍五入 floor是向下取整 ceiling 是向上取
用oracle sql对数字进行操作: 取上取整.向下取整.保留N位小数.四舍五入.数字格式化 取整(向下取整): select floor(5.534) from dual; select trunc(5.534) from dual; 上面两种用法都可以对数字5.534向下取整,结果为5. 如果要向上取整 ,得到结果为6,则应该用ceil select ceil(5.534) from dual; 四舍五入: SELECT round(5.534) FROM dual; ) FROM dua