How to maintain decimal precision in calculations
I need to sum 2 decimal values together, then divide by 2 and convert to string.
My calculation currently is trimming to 2 decimal places, but I want to keep as many decimals开发者_如何转开发 as I can.
city.Latitude = ( (lat.North + lat.South) / 2 ).ToString();
the values for lat.North and lat.South are like: 55.32342322
See here:
Standard Numeric Format Strings
http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx
You probably want to specify a "G" or "F" format specifier in this overload of the ToString()
method.
精彩评论