Show comma instead of point as decimal separator

前端 未结 5 1406
孤城傲影
孤城傲影 2020-12-31 15:30

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         


        
相关标签:
5条回答
  • 2020-12-31 16:11

    You can first replace thousand separator comma(,) to a Zero length string (''), and then you can replace Decimal('.') to comma(',') in the same select statement.

    0 讨论(0)
  • 2020-12-31 16:14

    To provide the appropriate culture info, in SQL 2012 there is the FORMAT() function. Here's an example:

    declare @f float = 123456.789;
    
    select
      [raw]      = str(@f,20,3)
     ,[standard] = cast(format(@f, 'N', 'en-US') as varchar(20))
     ,[European] = cast(format(@f, 'N', 'de-de') as varchar(20))
    

    returns

    raw                  |standard   |European   |
    ---------------------|-----------|-----------|
              123456.789 |123,456.79 |123.456,79 |
    

    You can also specify in the second parameter a custom format string with the same rules as for .NET.

    Docs: https://msdn.microsoft.com/en-US/library/hh213505.aspx

    0 讨论(0)
  • 2020-12-31 16:22
    DECLARE @euros money
    SET @euros = 1025040.2365
    SELECT REPLACE(CONVERT(varchar(30), @euros, 0), '.', ',')
    

    should do it (at least to get 1025040,24)

    0 讨论(0)
  • 2020-12-31 16:24

    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.

    0 讨论(0)
  • 2020-12-31 16:26

    You could use replace something like this:

    DECLARE @euros money 
    SET @euros = 1025040.2365
    
    SELECT REPLACE(REPLACE(CONVERT(varchar(30), @euros, 1),',',''),'.',',');
    

    SQL Fiddle Demo

    0 讨论(0)
提交回复
热议问题