var
x extended;
begin
x := pi; // x等于3.1415926535897932385
end;
8.round
功能说明:对一个实数进行四舍五入。
参考实例:
var
i, j: integer;
begin
i := round(1.25); // i等于1
j := round(1.62); // j等于2
end;
9.sqr
功能说明:取给定值的平方。
参考实例:
var
i: integer;
begin
i := sqr(3); // i等于9
end;
六、日期函数
对日期的处理,一般在有日期限制的共享、商业软件中经常使用到。如果你打算编写一款有日期限制的软件,熟悉使用下面的函数即可以实现。
1.date
功能说明:返回当前的日期。
参考实例:
procedure tform1.button1click(sender: tobject);
begin
label1.caption := '今天是:' + datetostr(date);
end;
label显示为:今天是2005年1月1日。
2.datetostr
功能说明:将日期型转换为字符型。
参考实例:
var
s: string;
begin
s := datetostr(date);
end;
3.datetimetostr
功能说明:将datetime型转换为字符型。
参考实例:
var
s: string;
begin
s := datetimetostr(now);
end;
4.dayofthemonth(所在单元:dateutils)
功能说明:获取指定日期的日。
参考实例:
label1.caption := inttostr(dayofthemonth(now));
假设当前日期为2005年1月2日,那么label将显示为2。
5.dayoftheweek(所在单元:dateutils)
功能说明:根据指定日期,获取星期几。
参考实例:
label1.caption := inttostr(dayofthemonth(now));
假设当前日期为2005年1月2日,那么label将显示为7。根据返回的值来判断是周几。7表示星期天,1为星期一,依类类推。
6.dayoftheyear(所在单元:dateutils)
功能说明:根据指定日期,获取天数。
参考实例:
label1.caption := inttostr(dayoftheyear(now));
假设当前日期为2005年1月2日,那么label将显示为2。表示是2005年的第2天。
7.dayof(所在单元:dateutils)
功能说明:根据指定的日期,返回日。
参考实例:
label1.caption := inttostr(dayof(date));
假设当前日期为2005年1月2日,那么label将显示为2。
8.isleapyear
功能说明:根据指定的年,判断是否为闰年。可使用yearof函数获取年。
参考实例:
procedure tform1.button1click(sender: tobject);
begin
if isleapyear(yearof(date)) then showmessage('是闰年')
else showmessage('不是闰年');
end;
9.monthof(所在单元:dateutils)
功能说明:根据指定的日期,返回月份。
参考实例:
label1.caption := inttostr(monthof(date));
假设当前日期为2005年1月2日,那么label将显示为1。
10.now
功能说明:返回当前日期及时间。
参考实例:
procedure tform1.button1click(sender: tobject);
begin
label1.caption := '现在是:' + datetimetostr(now);
end;
11.yearof(所在单元:dateutils)
功能说明:根据指定的日期,返回年。
参考实例:
label1.caption := inttostr(yearof(date));