您的位置:首页 > 编程语言 > Delphi

DELPHI的trunc函数

2014-01-04 13:52 344 查看


delphi函数trim()与trunc()区别:一个对字符串操作一个对数字操作

procedure TForm1.FormCreate(Sender: TObject);
var
f : double;
begin
f := 1.50;
showmessage(IntToStr(Trunc(f))); // 1 截取
showmessage(IntToStr(Round(f))); // 2 四舍五入
showmessage(IntToStr(Ceil(f))); // 2 向上取整
showmessage(IntToStr(floor(f))); // 1 向下取整

f := 1.40;
showmessage(IntToStr(Trunc(f))); // 1 截取
showmessage(IntToStr(Round(f))); // 1 四舍五入
showmessage(IntToStr(Ceil(f))); // 2 向上取整
showmessage(IntToStr(floor(f))); // 1 向下取整

f := -1.50;
showmessage(IntToStr(Trunc(f))); // -1 截取
showmessage(IntToStr(Round(f))); // -2 四舍五入
showmessage(IntToStr(Ceil(f))); // -1 向上取整
showmessage(IntToStr(floor(f))); // -2 向下取整

f := -1.40;
showmessage(IntToStr(Trunc(f))); // -1 截取
showmessage(IntToStr(Round(f))); // -1 四舍五入
showmessage(IntToStr(Ceil(f))); // -1 向上取整
showmessage(IntToStr(floor(f))); // -2 向下取整

// showmessage(IntToStr(Integer(f))); //不能这样 Error

// 截取就是你能看到的整数是多少就是多少
// 四舍五入, 这个不用多说了
// 向上取整, 比这个值大的 最小整数
// 向下取整, 比这个值小的 最大整数
end;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: