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 ...
Get Delphi in a Nutshell now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.