We have an import service for stores into our database. The latitude and longitude columns are not currently being formatted on import and have resulted in invalid values being inserted into our db. I therefore need to format any lat/long to have 3 places before the decimal and up to 6 after which I thought would be Format("###.######") but it doesn't seem to work. Input values such as 38.921322 or -12.235 have not seemed to conform to the formatting provided. Could anyone a bit more experienced in the area of C# string formatting shed light on how to achieve this? Thank you in advance.
2 Answers
Have you tried String.Format("{0:000.000000}", value);?
Console.WriteLine("{0:000.000000}", 123);
Outputs: 123.000000
1 Comment
user1769667
Thanks yall, just what I needed!
Use "0" instead of "#". From MSDN:
0 Replaces the zero with the corresponding digit if one is present; otherwise, zero appears in the result string.
# Replaces the "#" symbol with the corresponding digit if one is present; otherwise, no digit appears in the result string.
CultureInfoused in that process because some cultures uses comma instead of full stop as the decimal separator.