Wind Chill C# 最终编号需要更多位数

Wind Chill C# final number needs more digits

我一直在尝试解决这个关于风寒的公式,我得到了结果,但我需要小数点后更多的数字。无论我尝试什么都没有用。请帮忙!

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));
}

在此我得到最终数字 11.03490062551,但我想要 11.034900625509998。我做错了什么?

问题不在于 Math.RoundMath.Round 实际上会给你 11.034900625509991,我猜这就是你想要的。

问题出在 Console.WriteLine,它是导致精度损失的方法(因为在内部,它调用 string.Format 实际上导致了精度损失)。

要修复它,请像这样使用 round-trip format specifier

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

另请注意,windChill 的值对您来说应该足够了。无需调用 Math.Round.