home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PASCAL / REALST.ZIP / REALSTR.DOC next >
Encoding:
Text File  |  1990-07-05  |  2.1 KB  |  68 lines

  1.  
  2.      Files in this archive:
  3.     RealStr.Doc  - This file
  4.     RealStr.Pas  - Unit containing the RealToString () function
  5.     Test.    Pas  - RealToString example - type 0 or letter to exit
  6.  
  7.  
  8.     RealToString formats a floating point double, real, or single number
  9. into a string, according to the requested number of significant digits.
  10.  
  11.  
  12.     The number is displayed without the use of scientific notation, if
  13. it is possible to do so and still display the requested number of significant
  14. digits.  Also the number is rounded at the number of significant digits + 1
  15. and all trailing zeros are removed.
  16.  
  17.  
  18.     Because many numbers represented in a base 2 floating point format
  19. do not have an exact equivalent in base 10, any rounding done to a base 2
  20. number, which is then converted by Str() to a base 10 string, will be
  21. ineffective.  To bypass this problem, RealStr uses Str to convert the
  22. floating point number to a base 10 string and then rounds and formats the
  23. string.
  24.  
  25.  
  26.     Test.exe gives an example of how the routine is used and what the
  27. results look like for different significant digits.  Also, running Test.exe
  28. for several numbers will give the user an idea of why the TP reference guide
  29. says the significant digits of a single type are 7 TO 8, a real type 11 TO 12,
  30. and a double type 15 TO 16.
  31.  
  32.  
  33.         Example of using RealToString vs. Str :
  34.  
  35. var
  36. TempStr : string;
  37. Number    : real;
  38.  
  39.    begin
  40.    Number := 5.1;
  41.    Str (Number, TempStr);           { TempStr = '5.09999...E 0000'       }
  42.                        { 5.1 cannot be represented exactly  }
  43.                        { as a single or real type number    }
  44.    Number := 0.01;
  45.    Str (Number, TempStr);           { TempStr = '1.00000...E-0002'       }
  46.    end;
  47.  
  48.  
  49.    begin
  50.    Number := 5.1;
  51.    TempStr :=  RealToString (11, Number);      { TempStr = '5.1'         }
  52.  
  53.    Number := 0.01;
  54.    TempStr :=  RealToString (11, Number);      { TempStr = '0.01'        }
  55.    end;
  56.  
  57.  
  58.  
  59.     This routine is released to public domain by the author on 7/5/90.
  60.  
  61.     If you find any bugs in the routine, please drop me a note by
  62. Compuserve EMAIL.  Thanks.
  63.  
  64.  
  65.                    Rich Mullen    76566,1325
  66.  
  67.  
  68.