Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {*
- Same functionality as Round(x,n) in Delphi
- *}
- function RoundEx(x: Extended; N: byte): extended;
- var
- i, j : integer;
- begin
- if N > 10 then N := 10;
- if N > 0 then
- begin
- i := 1;
- for j:=1 to N do
- i := i * 10;
- result := Round(x * i) / i;
- end else
- result := Round(x);
- end;
- function TruncEx(x: Extended; N: byte): extended;
- var
- i, j : integer;
- begin
- if N > 10 then N := 10;
- if N > 0 then
- begin
- i := 1;
- for j:=1 to N do
- i := i * 10;
- result := Trunc(x * i) / i;
- end else
- result := Trunc(x);
- end;
- function CeilEx(x: Extended; N: byte): extended;
- var
- i, j : integer;
- begin
- if N > 10 then N := 10;
- if N > 0 then
- begin
- i := 1;
- for j:=1 to N do
- i := i * 10;
- result := Ceil(x * i) / i;
- end else
- result := Ceil(x);
- end;
- begin
- WriteLn(RoundEx(3.14159265, 4));
- WriteLn(TruncEx(3.14159265, 4));
- WriteLn(CeilEx(3.14159265, 4));
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement