STR

The STR function converts numbers to characters, with optional parameters for specifying the total length of the result, including the decimal point and the number of places after the decimal point.

Length and decimal parameters to STR (if supplied) should be positive. The default length is 10. The number is rounded to an integer by default or if the decimal parameter is 0. The specified length should be greater than or equal to the part of the number before the decimal point plus the number's sign (if any):

SELECT STR(123.45, 5, 1)

-----
123.5

(1 row(s) affected)

If the expression exceeds the specified length, the string returns ** for the specified length. For example:

SELECT STR(123.45, 2, 2)

--
**

(1 row(s) affected)

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

The use of STR() instead of CONVERT (char, numeric expressions) is often preferred because it gives explicit control over formatting.