Converts an integer or floating point number to a string System unit
 procedure Str ( const Number { : const Width {; var TargetString ) ;
The Str procedure converts an integer or floating point Number into a string, with optional basic formatting control.
By default, floating point numbers are shown in Exponential format, as here:
Specifying a Width guarantees that the output string will be at least that wide, with left blank padding added as appropriate.
When you specify Width, you can also specify Decimals for floating point numbers, which changes the display format to fixed as here:
Both Width and Decimals values may be provided by integer constants or variables.
Related commands
Format Rich formatting of numbers and text into a string
IntToStr Convert an integer into a string
StrToInt Convert an integer string into an Integer value
 Author links

 Buy Website Traffic at

 Buy Proxies at
 Download this web site as a Windows program.

Example code : A simple example
  intNumber   : Integer;
  floatNumber : Double;
  text        : string;

  // Assign values to our numbers
  intNumber   := 123;
  floatNumber := 987.654;

  // Display these numbers using vanilla 'Str'
  Str(intNumber, text);
  ShowMessage('intNumber   = '+text);
  Str(floatNumber, text);
  ShowMessage('floatNumber = '+text);

  // Now display using width and decimal place sizes
  Str(intNumber:10, text);
  ShowMessage('intNumber   = '+text);
  Str(floatNumber:10:4, text);
  ShowMessage('floatNumber = '+text);
Show full unit code
   intNumber   = 123
   floatNumber = 9.87654000000000E+0002
   intNumber   =        123
   floatNumber =   987.6540
Delphi Programming Neil Moffatt 2002 - 2016. All rights reserved.  |  Home Page