Janilabo

decacc

Sep 12th, 2013
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.66 KB | None | 0 0
  1. const
  2.   FLOAT = 17.84848484;
  3.  
  4. function DecAcc(x: Extended; accuracy: Integer): Extended;
  5. var
  6.   t: Extended;
  7.   s: string;
  8.   l: Integer;
  9. begin
  10.   if (accuracy > 0) then
  11.   begin
  12.     // FAILSAFES:
  13.     s := FloatToStr(DecRet(x));
  14.     if (s <> '0') then
  15.     begin
  16.       l := (Length(s) - 2);
  17.       if (accuracy > l) then
  18.         accuracy := l;
  19.     end else
  20.       accuracy := 0;
  21.     // ----------
  22.     t := Pow(10, accuracy);
  23.     Result := (Floor(x * t) / t);
  24.   end else
  25.     Result := Int(x);
  26. end;
  27.  
  28. var
  29.   i: Integer;
  30.  
  31. begin
  32.   ClearDebug;
  33.   for i := -1 to 9 do
  34.     WriteLn(FloatToStr(DecAcc(FLOAT, i)) + ' [FLOAT at Accuracy: ' + IntToStr(i) + ']');
  35. end.
Advertisement
Add Comment
Please, Sign In to add comment