Please start any new threads on our new
site at https://forums.sqlteam.com. We've got lots of great SQL Server
experts to answer whatever question you can come up with.
Author |
Topic |
Danger44
Starting Member
2 Posts |
Posted - 2011-03-01 : 23:58:16
|
Hello.I was reading up the geography data type, and everything I have read states that the latitude and longitude values are stored as floats. That is cool and all, but when I run this code, it suggests differently. Why is the lng and lat values from the geography object rounded down to just a few decimal places? Am I doing something stupid here?DECLARE @lng decimal(18,15) = -117.098121455566DECLARE @lat decimal(18,15) = 33.6023416376439DECLARE @g geography = geography::STGeomFromText('POINT(' + CAST(@lng as Varchar(50)) + ' ' + CAST(@lat as varchar(50)) + ')', 4326)print 'decimal 'print CAST(@lng as Varchar(50))print 'geography'print @g.LongOUTPUT:decimal -117.098121455566000geography -117.098Thanks in advance. |
|
Danger44
Starting Member
2 Posts |
Posted - 2011-03-03 : 19:51:23
|
Figured it out.Don't use 'print' to output the Lat and Long values from the geography object. It gets truncated.In addition, when inserting geography data types into a table, don't use floats as the lat and lng values. Use a decimal(18,15) if you want hardcore accuracy. For some reason floats get truncated once in the geography object. |
 |
|
|
|
|