Final Wind Chill C # Number Requires More Digits

I am trying to solve this formula about wind, I get the result, but I need more numbers after the decimal point. No matter what I tried, this did not work. Please, help!

static void Main()
{
    double temp = 20;
    double wind = 7;

    double windChill = 35.74 + 0.6215 * temp + (0.4275 * temp - 35.75) * Math.Pow(wind, 0.16);

    Console.WriteLine("so wind_chill = {0}", Math.Round(windChill, 15));
}

In this I get the final number 11.03490062551, but I want 11.034900625509998. What am I doing wrong?

+4
source share
1 answer

The problem is not Math.Round, Math.Roundin fact, will give you 11.034900625509991which I think you like.

The problem is Console.WriteLine, it is the method that causes the loss of accuracy (because inside it causes string.Format, which actually causes the loss of accuracy).

, round-trip :

Console.WriteLine("so wind_chill = {0:R}", Math.Round(windChill, 15));

, windChill . Math.Round.

+6

Source: https://habr.com/ru/post/1626792/


All Articles