In sql server, 5 is retained as a decimal, and any missing number is filled with 0

Background: Because users in the project have a requirement, relatively long data such as longitude and latitude need to retain 5 decimal places, and any missing 5 decimal places should be filled with 0.

For example: [114.140799999999999, 30.381399999999999] This group of longitude and latitude needs to be converted into [114.14079, 30.38139] or [114.1407, 30.381] This group of longitude and latitude needs to be converted into [114.14070, 30.38100].

This has been implemented in C# or js.

Here's how to implement it in sql:

Implementation idea: Convert the target longitude and latitude into a string through the CAST function, and then splice as many '0's as you need to retain decimal places. Just use the LEFT function to intercept 8-9 digits.


select LEFT(CAST((123.32888888823123412) AS nvarchar(50))+'00000',9)

 

select LEFT(CAST((123.32) AS nvarchar(50))+'00000',9)

 

 

Guess you like

Origin blog.csdn.net/qq_26695613/article/details/129011693