我一直试图解决关于风寒的这个公式,我得到了结果,但我需要在小数点后面有更多的数字.无论我尝试过什么都行不通.请帮忙!
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));
}
Run Code Online (Sandbox Code Playgroud)
在这里,我得到最终号码11.03490062551,但我想要11.034900625509998.我究竟做错了什么?
问题不在于Math.Round,Math.Round实际上会给你11.034900625509991我猜你想要的东西.
问题在于Console.WriteLine,它是导致精度损失的方法(因为在内部,它调用string.Format实际上导致精度损失).
要修复它,请使用如下所示的往返格式说明符:
Console.WriteLine("so wind_chill = {0:R}", Math.Round(windChill, 15));
Run Code Online (Sandbox Code Playgroud)
请注意,值windChill应该足够好.没有必要打电话Math.Round.