C #: round up to 2 decimal places for double variables

advertisements

This question already has an answer here:

  • Formatting a double to two decimal places 5 answers
  • Rounding double values in C# 4 answers
  • Rounding to 2 decimal points 3 answers

Is there any chance to format a double value after an operation to come up with only 2 decimal values? Because i am making a weather report and i'm getting the average of weather data per 5 minutes and i want to make it formal to have only 2 decimal places.

Which instead of having 10240.8999 i could have 10240.90. Any thoughts or suggestion?


Round with 2 decimals and convert to string to force 2 decimals

string rounded = String.Format("{0:f2}", Math.Round(10240.8999, 2));

Gives 10240.90