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;