Janilabo

Untitled

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