# str

### Description

Returns the character equivalent of the specified number.

### Syntax

str(*approx_numeric *[, *length *[, *decimal*] ])

### Parameters

*approx_numeric*
is any approximate numeric (*float*, *real*,
or *double* *precision*) column
name, variable, or constant expression.

*length*
sets the number of characters to be returned (including
the decimal point, all digits to the right and left of the decimal
point, and blanks). The default is 10.

*decimal*
sets the number of decimal digits to be returned.
The default is 0.

### Examples

*Example 1*

select str(1234.7, 4)

----
1235

*Example 2*

select str(-12345, 6)

------
-12345

*Example 3*

select str(123.45, 5, 2)

-----
123.5

### Usage

**str**,
a string function, returns a character representation of the floating
point number. For general information about string functions, see “String functions”.

*length* and *decimal *are
optional. If given, they must be non-negative. **str** rounds
the decimal portion of the number so that the results fit within
the specified length. The length should be long enough to accommodate
the decimal point and, if negative, the number’s sign.
The decimal portion of the result is rounded to fit within the specified
length. If the integer portion of the number does not fit within
the length, however, **str** returns a row of asterisks
of the specified length. For example:

select str(123.456, 2, 4)

--
**

A
short *approx_numeric* is right justified
in the specified length, and a long *approx_numeric* is
truncated to the specified number of decimal places.

If *approx_numeric* is
NULL, returns NULL.

### Standards

**SQL92** – Compliance level: Transact-SQL
extension.

### Permissions

Any user can execute** str**.

### See also

**Functions** abs, ceiling, floor, round, sign