0

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
  • 1
    Are you parsing or formatting numbers? Be aware of the CultureInfo used in that process because some cultures uses comma instead of full stop as the decimal separator. Commented Nov 19, 2013 at 15:50
  • 2
    Do you store LAT/LONG as VARCHAR in your database? Commented Nov 19, 2013 at 15:52

2 Answers 2

4

Have you tried String.Format("{0:000.000000}", value);?

Console.WriteLine("{0:000.000000}", 123);

Outputs: 123.000000

Sign up to request clarification or add additional context in comments.

1 Comment

Thanks yall, just what I needed!
4

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.