显示逗号而不是点作为小数分隔符
我只想在德国获得正确的数字格式,所以我需要将逗号显示为小数点分隔符而不是点.但是这个……
I just want to get the right number format here in germany, so i need to show commas as decimal separator instead of points. But this...
DECLARE @euros money
SET @euros = 1025040.2365
SELECT CONVERT(varchar(30), @euros, 1)
显示 1,025,040.24
而不是 1.025.040,24
(或 1025040,24
).在 C# 中提供适当的 CultureInfo
很简单,但如何在 T-SQL 中做到这一点?
Displays 1,025,040.24
instead of 1.025.040,24
(or 1025040,24
). In C# it would be simple to provide the appropriate CultureInfo
but how to do it in T-SQL?
我真的需要使用 REPLACE
吗?但即便如此,如何正确替换1,025,040.24
?
Do i really need to use REPLACE
? But even if, how to replace 1,025,040.24
correctly?
推荐答案
好吧,据我所知,没有特定于文化的转换选项可用.
Well, as far as I know, there are no culture-specific options for convert available.
所以你可以使用替换来做到这一点(是的,它看起来有点难看......)
So you can do it using replaces (yes, it looks a bit ugly...)
select
replace(replace(replace(convert(varchar(30), @euros, 1), ',', '|'), '.', ','), '|', '.')
想法:先把逗号换成东西,再把点换成逗号,再把东西"换回点.
Idea: first change comma to something, then change dot to comma, and then "something" back to dot.
相关文章