When you want to convert from float or Real to character data, using the STR string function was usually more u Seful than CAST (). This was because STR enables more control over formatting.
Syntax
STR [] ] )
Arguments
-
- Float_expression
-
-
is an expression of approximate numeric (float) data type with a decimal point.
-
- Length
-
-
is the total length. This includes the decimal point, sign, digits, and spaces. The default is ten.
-
- Decimal
-
-
is the number of places to the "right" of the decimal point. decimal must is less than or equal to 16. If Decimal is more than and the result is truncated to sixteen places to the right of the decimal point.
Return Type Varchar,to convert to Unicode data, use STR inside a convert or CAST conversion functionExample
SELECT STR (123.4561);
The result is 123.5, the type is varchar
The STR function converts a decimal number to a varchar type