Aniket Narvankar

Aniket Narvankar

  • 522
  • 2.1k
  • 575.7k

C Sharp .Net

Jul 12 2022 1:51 PM

I have a requirement in which need to store latitude values only upto 6 decimal places after decimal point without rounding off

for example

latitude value is: 32.8912345  then should store as 32.891234

latitude value is 33.2345 then should store as itsi 33.2345 as it ihas less than six digits after decimal point.

in sql server i intially kept data type of latitude column as varchar(11)

in c sharp also i used string variable

and have written the following code

 if (lat.Contains("."))
                    {
                        string[] tempStr1 =  lat.Split('.');

                        string GoogleLatitude=string.Empty;
                        if (tempStr1[1].Length > 6)
                        {
                          GoogleLatitude = tempStr1[0] + "." + tempStr1[1].Substring(0, 6);
                        }
                        else
                        {
                            GoogleLatitude =  lat;
                        }
                    }
                    else
                    {
                         GoogleLatitude =  lat;
                    }

please do let me know how this can be achieved by using deciam(9,2) as datatype for sql column and without using split functions.

 


Answers (1)