SqlFunctions.StringConvert doesn't work with doubles

前端 未结 1 547
忘了有多久
忘了有多久 2021-01-15 12:13

I have something like that in code

SqlFunctions.StringConvert( (double?) x.Latitude)

but it returns an integer always although it has a lat

1条回答
  •  走了就别回头了
    2021-01-15 12:26

    SqlFunctions.StringConvert(double?) returns an integer converted to string. To return a decimal value, you need to provide the other overload SqlFunctions.StringConvert(double? vaue, int length, int decimals) as follows:

    SqlFunctions.StringConvert( (double?) x.Latitude, 20, 5)
    
    // If x.Latitude = 34.75, then the result will be "34.75000"
    

    From the STR documentation:

    The number is rounded to an integer by default or if the decimal parameter is 0.

    References:
    SqlFunctions.StringConvert Method (Nullable)
    SqlFunctions.StringConvert Method (Nullable, Nullable, Nullable)
    STR (Transact-SQL)

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