Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {*
- Truncates an integer.
- *}
- function TruncInt(x, n: Integer): Integer;
- var
- i,digits,v: Integer;
- m:boolean;
- begin
- if x < 0 then begin
- x := -x;
- m := True;
- end;
- v := 1;
- while v < x do
- begin
- v := v * 10;
- inc(digits);
- if digits >= 9 then Break;
- end;
- n := Abs(Min(n,digits) - digits);
- for i:=0 to n-1 do
- x := (x div 10);
- if not(m) then Result := x
- else Result := -x;
- end;
- {*
- 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;
- begin
- WriteLn(TruncInt(314159265, 5));
- WriteLn(RoundEx(3.14159265, 4));
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement