Converting float to varchar with correct decimal separator

天涯浪子 提交于 2020-01-10 05:21:06

问题


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),'.',',')

回答1:


  • 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



来源:https://stackoverflow.com/questions/9310007/converting-float-to-varchar-with-correct-decimal-separator

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!