Mohamed Naguib
Mohamed Naguib

Reputation: 1730

SqlFunctions.StringConvert doesn't work with doubles

I have something like that in code

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

but it returns an integer always although it has a latitude value.

any help?

Upvotes: 3

Views: 6426

Answers (1)

Wagner DosAnjos
Wagner DosAnjos

Reputation: 6374

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)

Upvotes: 3

Related Questions