LLI Wiki — My Digital Knowledge Base

Avoid scientific notation when converting numbers to text

Convert numbers to text without scientific notation in T-SQL, using a DECIMAL cast or the STR function.

Converting a float or a large number to a character type can return scientific notation. The statements below return plain decimal text instead.

Integer and money values

Cast the value to a numeric type and convert it to varchar:

convert(varchar(100),cast(FC_ID as int))
convert(varchar(100),cast(FC_ID as money))

Float values

Cast the float to decimal with a fixed scale before converting, or use STR with a length and a number of decimals:

SELECT CONVERT(varchar(100), CAST(@testFloat AS decimal(38,2)))
SELECT STR(@testFloat, 38, 2)

Notes

Mastodon LLIMastodon SocialFosstodon