Math.Round() 在 Windows Phone 上不起作用.为什么
本文关键字:Phone 不起作用 为什么 Windows Round Math | 更新日期: 2023-09-27 18:32:37
我试图使用 Math.Round()
舍入值。但它不起作用。我可以知道为什么吗?这里有人知道确切的原因吗?
double num = 0;
if (double.TryParse(number.Text, out num) && num > 0 && num < 60)
{
Math.Round(num);
browser.Navigate(new Uri("/file" + num + ".html", UriKind.Relative));
}
else
{
MessageBox.Show("Expected Input Range: 1 to 59");
}
Math.Round
返回舍入值,因此您必须将新值重新分配给num
例:
double num = 0;
if (double.TryParse(number.Text, out num) && num > 0 && num < 60)
{
num = Math.Round(num);
browser.Navigate(new Uri("/file" + num + ".html", UriKind.Relative));
}
else
{
MessageBox.Show("Expected Input Range: 1 to 59");
}
但我有一种感觉,在这种情况下,你不想要任何小数位,你只是投射int
browser.Navigate(new Uri("/file" + (int)num + ".html", UriKind.Relative));
测试:
double num = 34.5;
num = Math.Round(num); // returns 34.0
double num = 34.5;
int newNum = (int)num; // returns 34