program roundingtointeger;
{$codepage UTF8}
uses math;
var
some_int:real;
some_real:real;
I,Count,guess : Longint;
R : Real;
begin
some_int :=375.5;
some_real:=375.4;
writeln('PI=',pi);
writeln('Some_int =' ,trunc(some_int));
writeln('some_int=',round(some_int)) ;
writeln('some_real=',trunc(some_real));
writeln('some_real',round(some_real));
writeln('Ceil');
Writeln(Ceil(-3.7)); // should be -3
Writeln(Ceil(3.7)); // should be 4
Writeln(Ceil(-4.0)); // should be -4
writeln('floor');
Writeln(floor(-3.7)); // should be -4
Writeln(floor(3.7)); // should be 3
Writeln(floor(-4.0)); // should be -4
writeln('Round');
WriteLn( Round(8.7) );//9
WriteLn( Round(8.5) );//8
WriteLn( Round(8.3) );//8
WriteLn( Round(7.5) );//8
WriteLn( Round(5.4) );//5
WriteLn( Round(5.5) );//6
WriteLn( Round(5.6) );//6
// examples of "bankers rounding" - .5 is adjusted to the nearest even number
WriteLn( Round(2.5) ); //2
WriteLn( Round(3.5) );//4
writeln('pred or succ of c');
writeln('succ=',succ('c'));
writeln('pred=',pred('c'));
writeln('pred or succ of 0');
writeln('succ=',succ(0));
writeln('pred=',pred(0));
writeln('pred or succ of "0"');
writeln('succ=',succ('0'));
writeln('pred=',pred('0'));
writeln('设置四舍五入模式');
writeln('Round to',roundto(2.5,0));
setroundmode(rmNearest);
writeln('2.5 Nearest=',roundto(2.5,0));
setroundmode(rmDown);
writeln('2.5 roundDown=',roundto(2.5,0));
setroundmode(rmUp);
writeln('2.5 roundUP=',roundto(2.5,0));
setroundmode(rmTruncate);
writeln('2.5 roundTruncate=',roundto(2.5,0));
//正常的四舍五入,请使用Math.SetRoundMode修改
Math.SetRoundMode(rmUp);
write(trunc(roundto(-2.5,0)),' ');
write(trunc(roundto(-1.5,0)),' ');
write(trunc(roundto(-0.5,0)),' ');
write(roundto(0.5,0),' ');
write(trunc(roundto(0.5,0)),' ');
write(trunc(roundto(1.5,0)),' ');
writeln(trunc(roundto(2.5,0)));
readln();
end.