delphi的取整函数round、trunc、ceil和floor
来源:互联网 发布:淘宝刷客怎么判刑2017 编辑:程序博客网 时间:2024/06/09 17:36
首先引入math单元
uses math;
1.Round(四舍六入五留双)
功能说明:对一个实数进行四舍五入。(按照银行家算法)
例:
var
i, j: Integer;
begin
i := Round(1.5); // i等于2
j := Round(2.5); // j等于2
end;
在Delphi中使用Round函数得到的答案有时与我们所预期的会不太一样:采用的是四舍六入五留双。即当舍或入位大于或小于五时按四舍五入来处理
,而当舍或入位等于五时,就要看前面一位是什么,根据奇进偶不进,它总是返回一个偶数值。
例:
i:= Round(11.5)//i等于12
i:= Round(10.5)//i等于10
这种Round其实是按照银行家算法,统计学上一般都用这种算法,比传统的"四舍五入"要科学。
如果要使用传统的"四舍五入"方法,可以使用下面函数:
function RoundClassic(R: Real)
2.trunc(取得X的整数部分)
如:trunc(-123.55)=-123, floor(123.55)=123
3.ceil(取得大于等于X的最小的整数)
如:ceil(-123.55)=-123, ceil(123.15)=124
4.floor(取得小于等于X的最大的整数)
如:floor(-123.55)=-124,floor(123.55)=123
- delphi的取整函数round、trunc、ceil和floor
- delphi的取整函数round、trunc、ceil和floor
- delphi的取整函数round、trunc、ceil和floor
- delphi的取整函数round、trunc、ceil和floor
- delphi的取整函数round、trunc、ceil和floor
- delphi的取整函数round、trunc、ceil和floor
- delphi的取整函数round、trunc、ceil和floor
- delphi的取整函数round、trunc、ceil和floor
- delphi的取整函数round、trunc、ceil和floor
- delphi的取整函数round、trunc、ceil和floor
- delphi的取整函数round、trunc、ceil和floor
- delphi的取整函数round、trunc、ceil和floor
- delphi的取整函数round、trunc、ceil和floor
- delphi的取整函数round、trunc、ceil和floor
- delphi的取整函数round、trunc、ceil和floor
- delphi的取整函数round、trunc、ceil和floor
- delphi的取整函数round、trunc、ceil和floor
- delphi的取整函数round、trunc、ceil和floor
- usb 转串口 链接板子
- object-C 判断字符串是否含有特殊字符
- Oracle复制某一个字段 批量修改(我们可以在插入的时候修改)
- java面试题及答案
- Mysql 存储过程,触发器,视图 学习记录
- delphi的取整函数round、trunc、ceil和floor
- Shader快速复习:Per Pixel Lighting(逐像素光照)
- 二分匹配总结
- NAND Flash和NOR Flash的比较
- C#彩色图像灰度化算法
- ubuntu虚拟机下搭建tftp服务器
- 现在做奢侈品电子商务时机成熟了吗?
- 《HP大中华区总裁孙振耀退休感言》
- 专题一、Linux设备驱动模型