Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
Variety of Floating point functions Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
01-Nov-02
Category
Algorithm
Language
Delphi 3.x
Views
109
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			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;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC