Str function

Official Content
This documentation is valid for:

To convert a numeric expression into a string.

Syntax

Str( n1 [ , n2 [ , n3 ] ] )

Type Returned
Character

Where:
n1
Is the numeric expression to be converted into a string.

n2
Numeric expression. It is the total length of n1, including numeric sign and decimal point.
 
n3
Numeric expression. It is the number of decimal places

Description

Returns a character string, aligned to the right, which represents n1 in string format. If you specify fewer decimal places than those in the numeric expression n1, the value is rounded. 

Constraints:
0 <= n2 <= 18

In Visual FoxPro the limit for n3 is: 18 minus one place for the sign, and minus the decimal places. In other words, a limit of 18 places for the whole numeric expression.

In COBOL the limit for n3 is 2.

Note

Insignificant zeros are truncated.

10 = Default value for n2
0 = Default value for n3

Examples

Str(1.25) = " 1" 

Note the blank spaces due to the right alignment.

Str(-1.25,10,2) = " -1.25" 

Note the blank spaces due to the right alignment.

Str(-1.25,2,1) = "-1"
Str(-1.25,5,1) = " -1.3"

Note the blank space due to the right alignment.

Str(-1.25,5,2) = "-1.25"
Str(12345678901234.12,13,2) = "*************"
Str(1234.4,5,1) = "1234" 

Here 1234.5 is rounded and the decimal is discarded because it ends up having a zero value.

Scope

Objects    Procedure object, Transaction object, Web Panel object

See also

Concat function
Substr Function
Val function





Was this page helpful?
What Is This?
Your feedback about this content is important. Let us know what you think.