[整数型への変換]

それぞれの型を、整数型に変換します。

実数の整数化には以下の関数があります。

関数名  戻型/ 値   1    0.1    0.8 0.4999    0.5   -0.1   -0.8   -0.5 -0.5001	
Int     Extended    1      0      0      0      1      0      0      0       1
Floor   Integer     1      0      0      0      0     -1     -1     -1      -1
Trunc   Int64       1      0      0      0      0      0      0      0       0
Ceil    Integer     1      1      1      1      1      0      0      0       0	
Round   Int64       1      0      1      0      0      0     -1      0      -1	

【ソースコード】 [tips0010.pas]
program tips0010;
{$APPTYPE CONSOLE}
uses SysUtils,Variants;
var
 a:Double;      //実数型
 b:TDateTime;    //日付型
 c:Boolean;      //論理型
 d:String;      //文字列型
 e,f,g,h:Integer;  //整数型
begin
 a:=110.23;
 b:=VarToDateTime('2009/05/23 19:00:00');
 c:=True;
 d:='-2';

 e:=Trunc(a);    //小数点以下が切り捨てられる
 f:=Trunc(b);    //日付部分のみとなる
 g:=Ord(c);      
 h:=StrToInt(d);

 WriteLn(IntToStr(e));
 WriteLn(DateTimeToStr(f));
 WriteLn(IntToStr(g));
 WriteLn(IntToStr(h));
end.
【コンパイル&実行】 [tips0010.bat]
dcc32 tips0010.pas 
tips0010.exe  > tips0010.txt
pause
【実行結果】 [tips0010.txt]
110
2009/05/23
1
-2