Show: Delphi C++
Display Preferences


From RAD Studio API Documentation
Jump to: navigation, search


procedure Str(const X [: Width [:Decimals]]; var S: String);



Type Visibility Source Unit Parent
procedure public System.pas System System


Formats a string and returns it to a variable.

In Delphi code, Str converts an integer-type or real-type expression to a string, according to the Width and Decimals formatting parameters. Width represents the length of the resulting string. Decimals sets the number of places after the decimal point. Both of these parameters are integer-type expressions. The effect of this procedure is similar to Write, except the result is passed to a variable instead of being written to a text file.

X is an integer-type or real-type expression. Width and Decimals are integer-type expressions. S is a string-type variable or a zero-based character array variable, if extended syntax is enabled.

Example (Delphi):

  aNumber: real;
  myString: string;
aNumber := 123456.789;
Str(aNumber: 16: 6, myString); // Predefined string length: 16. Decimal places: 6.
Writeln(myString); // The output is: '   123456.789000'
Notes: However, on using this procedure, the compiler may issue a warning: W1057 Implicit string cast from '%s' to '%s' (Delphi).

If a string with a predefined minimum length is not needed, try using the IntToStr function instead.

See Also

Code Examples

Personal tools