显示逗号而不是点作为小数点分隔符 [英] Show comma instead of point as decimal separator
问题描述
我只想在德国这里获得正确的数字格式,所以我需要将逗号显示为小数点分隔符而不是点。但这...
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.
因此,您可以使用replaces(是的,看起来有点丑陋... )
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.
这篇关于显示逗号而不是点作为小数点分隔符的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!