Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.0k views
in Technique[技术] by (71.8m points)

sql server 2008 - Converting float to varchar with correct decimal separator

Hi i'm living in austria and we use the , as decimal separator.

It seems to be impossible to convert the float to varchar with the correct separator according to the language/collation setting?

Is this a bug?

set language german --makes no difference in this case
declare @f float = 4.5
select @f --output in my management studio is 4,5 
          --according to the regional os settings this is correct

select convert(varchar,@f) -- output: 4.5 not correct

one solution, but not ideal I think

select replace(convert(varchar,@f),'.',',')
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)
  • SSMS formats the float type based on your regional settings
  • The SQL Engine language setting doesn't affect what separators are used

Correctly, you should leave numbers as numbers and format in the client.
This is what SSMS is doing for you

Also see SQL server with german regional settings


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

1.4m articles

1.4m replys

5 comments

57.0k users

...