Floating point numbers are represented by the float data type in SQL Server. Operations, such as string concatenation, require converting a floating point number to a string to avoid data type conversion errors. This can quite easily be achieved through the use of the T-SQL "CAST()" function.
- Skill level:
Other People Are Reading
Open SQL Server Management Studio.
Open a new query window.
Convert a floating-point number to a string using the CAST() function by executing the following query statement. Replace "<float>" with any floating point number and "<length>" with the total number of digits in the number plus the decimal point:
SELECT CAST(<float> AS CHAR(<length>))
Tips and warnings
- The "CONVERT()" function can be substituted for "CAST()", if preferred. The number can be converted to a VARCHAR instead of a CHAR, if preferred.
- Casting a floating point number to a CHAR of fewer characters than the number of digits and decimal in the number will result in an arithmetic overflow error.
- 20 of the funniest online reviews ever
- 14 Biggest lies people tell in online dating sites
- Hilarious things Google thinks you're trying to search for