Janilabo

Untitled

Sep 12th, 2013
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 0.50 KB | None | 0 0
  1. const
  2.   DECIMALS = 4; // "accuracy"
  3.   FLOAT = 1.23456;
  4.  
  5. function FracAcc(x: Extended; a: Integer): Extended;
  6. var
  7.   d: Extended;
  8.   z: Boolean;
  9. begin
  10.   Result := Int(x);
  11.   if (a > 0) then
  12.   begin
  13.     d := DecRet(x);
  14.     z := (d < 0.1);
  15.     if z then
  16.       d := (d + 0.1);
  17.     Result := (Result + StrToFloatDef(('.' + Copy(FloatToStr(d), 3, a)), 0));
  18.     if z then
  19.       Result := (Result - 0.1);
  20.   end else
  21.     Result := 0;
  22. end;
  23.  
  24. begin
  25.   WriteLn(FloatToStr(FracAcc(FLOAT, DECIMALS)));
  26. end.
Advertisement
Add Comment
Please, Sign In to add comment