gpt4 book ai didi

sql-server-2008 - 使用正确的小数分隔符将 float 转换为 varchar

转载 作者:行者123 更新时间:2023-12-04 07:09:05 25 4
gpt4 key购买 nike

您好,我住在奥地利,我们使用 , 作为小数点分隔符。

根据语言/排序规则设置,使用正确的分隔符似乎无法将 float 转换为 varchar?

这是一个错误吗?

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

一个解决方案,但我认为并不理想

select replace(convert(varchar,@f),'.',',')

最佳答案

  • SSMS 根据您的区域 设置格式化float 类型
  • SQL 引擎语言设置不影响使用的分隔符

正确地,您应该在客户端中保留数字作为数字和格式。
这就是 SSMS 为您所做的

另见 SQL server with german regional settings

关于sql-server-2008 - 使用正确的小数分隔符将 float 转换为 varchar,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9310007/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com