-2

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?

Solem
  • 17
  • 2
  • 7

2 Answers2

0

In .NET, the way to do this is:

var rounded = Math.Round(valueToRound, 2);

for decimal variables:

var rounded = Decimal.Round(valueToRound, 2);
JLRishe
  • 95,368
  • 17
  • 122
  • 158
-1

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

Flat Eric
  • 7,827
  • 9
  • 34
  • 44