Returns the character equivalent of the specified number.
str(approx_numeric[, length [, decimal]])
is any approximate numeric (float, real, or double precision) column name, variable, or constant expression.
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.
sets the number of decimal digits to be returned. The default is 0.
select str(1234.7, 4)
---- 1235
select str(-12345, 6)
------ -12345
select str(123.45, 5, 2)
----- 123.5
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 nonnegative. 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.
ANSI SQL – Compliance level: Transact-SQL extension.
Any user can execute str.