这个问题被问了多次,但我无法让它工作......
我正在开发一个程序来计算两点之间的距离,并计算一个单位绕它走的时间......
这是我需要做的简化版本:
x = 24
y = 23
Root of (24² + 23²) = 33.24 fields
33.24 x 30 = 997,2 minuts
997,2/60 = 16,62 hours
16: (60*0.62) = 16:37,2
16:37: (60*0,2) = 16:37:12
所以我在 C# 中有这段代码,但它不起作用:
first_town = "35|629";
second_town = "59|606";
snelheidUnit = 30;
string[] firstTownSplit = first_town.Split('|');
string[] secondTownSplit = second_town.Split('|');
int firstTownPart1 = Convert.ToInt32(firstTownSplit[0]);
int firstTownPart2 = Convert.ToInt32(firstTownSplit[1]);
int secondTownPart1 = Convert.ToInt32(secondTownSplit[0]);
int secondTownPart2 = Convert.ToInt32(secondTownSplit[1]);
int verschilX = firstTownPart1 - secondTownPart1;
int verschilY = firstTownPart2 - secondTownPart2;
double aantalVelden = Math.Sqrt((Math.Pow(verschilX, 2) + Math.Pow(verschilY,2))); // Fields
double aantalMinuten = aantalVelden * snelheidUnit; // Minuts
double aantalUren = aantalMinuten / 60; // Hours
TimeSpan time = TimeSpan.FromHours(aantalUren);
string FinalTime = string.Format("{0:D2}d:{1:D2}h:{2:D2}m:{3:D2}s:{4:D3}ms", time.Days, time.Hours, time.Minutes, time.Seconds, time.Milliseconds);
预期的输出应该是:00d:16h:37m:12s:772ms
但是是:00d:16h:37m:14s:772ms
差异为 2 秒。瓶颈是什么?为什么预期输出和实际输出之间有 2 秒的差异?