简体   繁体   中英

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM