Returns character data converted from numeric data.

STR (float_expression [ , length [ , decimal ] ] )

Arguments

  • float_expression
    An expression of that can be implicitly converted to float.

    Do not use a function or subquery as the float_expression.

  • length
    The total length, including decimal point, sign, digits, and spaces. The default is 10. The length argument must be of a data type that can be implicitly converted to int.

  • decimal
    The number of places to the right of the decimal point. The decimalargument must be of a data type that can be implicitly converted to int. The default is 0.

nvarchar

Example

The following example converts expressions consisting of five digits and a decimal point to six-position character strings. The fractional part of the first number is rounded to one decimal place. The fractional part of the second number is rounded to two decimal places. The third number is returned without a decimal place.

CREATE TABLE ExampleTable (Col1 float, Col2 float, Col3 float);
INSERT INTO ExampleTable Values(123.45, 123.45, 123.45);
SELECT STR(Col1, 6,1), STR(Col2, 6,2), STR(Col3) FROM ExampleTable;