0

Example that calculates area of trapezoid

Input 5, 7, 12, Output 72.0000000
Input 8.5, 4.3, 2.7, Output 49.5000000
Input 100, 200, 300,    Output 45000.0000000
Input 5, 7, 12, Output 72.0000000
Input 0.222, 0.333, 0.555,  Output 0.1540125

I need the answer to look like the above always to have 7 digits behind it.

Soner Gönül
  • 97,193
  • 102
  • 206
  • 364

2 Answers2

0
string.Format("{0:0.0000000}", 34.5223423523542);
//  34.5223424

string.Format("{0:N7}", 34.5223423523542);
//  34.5223424
Nick Larsen
  • 18,631
  • 6
  • 67
  • 96
0

If you are going to be displaying only a certain number of digits, you may want to round the result prior to display it.

double number = 1.23456789;
string output = Math.Round(number, 7, MidpointRounding.AwayFromZero).ToString("N7")

The value of output above will be 1.2345679.

user1666620
  • 4,800
  • 18
  • 27