Name

Str Procedure

Syntax

procedure Str(const Value; var S: string);
procedure Str(const Value:Width; var S: string);
procedure Str(const Value:Width:Precision; var S: string);

Description

The Str procedure formats a number as a string, similar to Write, except that it “writes” to the string S. The Value can be any numeric or Boolean expression. The string S can be a long string, short string, or zero-based character array. Str is not a real procedure.

Width and Precision can be any integer expressions. Width specifies the minimum size of the string representation of Value, and Precision specifies the number of places after the decimal point of a floating-point number.

Str uses as many characters as it needs, so Width is just the suggested minimum width. If the number requires fewer than Width characters, Str pads the string on the left with blanks. If you do not supply a Width, Delphi uses 1 as the minimum width for integers and it prints floating-point numbers as 26 characters in the following form:

'-1.12345678901234567E+1234'

If the Value is a floating-point number, Str reduces the number of decimal places to fit the value into a string that uses at most Width characters. Str always uses at least one digit after the decimal place, though. You can also supply a Precision, which tells Str how many decimal places to use after the decimal point. If you supply a Precision, Str uses fixed-point notation instead of exponential notation.

Tips and Tricks

  • The SysUtils unit has several functions that provide more flexibility than Str.

  • If the ShortString is too short to represent the entirety of Value, Str stops when it fills the string and does not report an error.

Example

procedure ShowInfo;
var
  S: string;
begin
  Str(List.Count, S);
  ShowMessage(S + ' items in the list.'),
end;

See Also

String Type, Val Procedure, Write Procedure
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset