Show comma instead of point as decimal separator

前端 未结 5 1448
孤城傲影
孤城傲影 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: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

提交回复
热议问题