home *** CD-ROM | disk | FTP | other *** search
-
- Files in this archive:
- RealStr.Doc - This file
- RealStr.Pas - Unit containing the RealToString () function
- Test. Pas - RealToString example - type 0 or letter to exit
-
-
- RealToString formats a floating point double, real, or single number
- into a string, according to the requested number of significant digits.
-
-
- The number is displayed without the use of scientific notation, if
- it is possible to do so and still display the requested number of significant
- digits. Also the number is rounded at the number of significant digits + 1
- and all trailing zeros are removed.
-
-
- Because many numbers represented in a base 2 floating point format
- do not have an exact equivalent in base 10, any rounding done to a base 2
- number, which is then converted by Str() to a base 10 string, will be
- ineffective. To bypass this problem, RealStr uses Str to convert the
- floating point number to a base 10 string and then rounds and formats the
- string.
-
-
- Test.exe gives an example of how the routine is used and what the
- results look like for different significant digits. Also, running Test.exe
- for several numbers will give the user an idea of why the TP reference guide
- says the significant digits of a single type are 7 TO 8, a real type 11 TO 12,
- and a double type 15 TO 16.
-
-
- Example of using RealToString vs. Str :
-
- var
- TempStr : string;
- Number : real;
-
- begin
- Number := 5.1;
- Str (Number, TempStr); { TempStr = '5.09999...E 0000' }
- { 5.1 cannot be represented exactly }
- { as a single or real type number }
- Number := 0.01;
- Str (Number, TempStr); { TempStr = '1.00000...E-0002' }
- end;
-
-
- begin
- Number := 5.1;
- TempStr := RealToString (11, Number); { TempStr = '5.1' }
-
- Number := 0.01;
- TempStr := RealToString (11, Number); { TempStr = '0.01' }
- end;
-
-
-
- This routine is released to public domain by the author on 7/5/90.
-
- If you find any bugs in the routine, please drop me a note by
- Compuserve EMAIL. Thanks.
-
-
- Rich Mullen 76566,1325
-
-