Author: Ronald Buster Variety of Floating point functions Answer: 1 2 // FloatDecimals 3 4 function FloatDecimals(Value, decimals: extended): extended; 5 var 6 Factor: extended; 7 begin 8 Factor := Power(10, Decimals); 9 Value := Value * Factor; 10 Value := Round(Value); 11 Value := Value / Factor; 12 Result := Value; 13 end; 14 15 // FloatRound ( Same as FloatDecimals but more aqurate ) 16 17 function FloatRound(Value, Digits: extended): extended; 18 var 19 Factor: extended; 20 begin 21 Factor := Power(10, Digits); 22 Result := (Value * Factor) + 0.5; 23 Result := Trunc(Result) / Factor; 24 end; 25 26 // FloatCompare 27 28 function FloatCompare(Value1, Value2: Extended): Boolean; 29 begin 30 Result := False; 31 if abs(Value1 - Value2) < 0.00001 then 32 Result := True; 33 end; 34 35 // FloatLessEqual 36 37 function FloatLessEqual(Value1, Value2: extended): Boolean; 38 begin 39 Result := False; 40 if (abs(Value1 - Value2) < 0.00001) or (Value1 < Value2) then 41 Result := True; 42 end; 43 44 // FloatGreateEqual 45 46 function FloatGreaterEqual(Value1, Value2: extended): Boolean; 47 begin 48 Result := False; 49 if (abs(Value1 - Value2) < 0.00001) or (Value1 > Value2) then 50 Result := True; 51 end; 52 53 // FloatStr (Format a extended value towards a string with 2 decimals ) 54 55 function FloatStr(Value: extended): string; 56 begin 57 Result := FloatToStrF(Value, ffFixed, 18, 2); 58 end; 59 60 // FloatStr ( Format a extended value towards a string with specified decimals ) 61 62 function FloatStr(Value: extended; Digits: Byte): string; 63 begin 64 Result := FloatToStrF(Value, ffFixed, 18, Digits); 65 end;