[英]Result of Math.round() is ignored
Math.round(argument)
returns a number that is rounded from the argument. Math.round(argument)
返回一个从参数四舍五入的数字。
In your example you ignore the returned value.在您的示例中,您忽略返回的值。
You probably meant to write:你可能想写:
odleglosc = Math.round(odleglosc);
x = Math.round(x);
Otherwise if you just write Math.round(x);
否则如果你只写
Math.round(x);
Java will make the calculation and have no variable to assign it to, and gets thrown away. Java 将进行计算并且没有变量可以分配给它,并被丢弃。
Math.round()
does not modify your variable because a double
the value is passed to the function (compare all-by-value vs call-by-reference). Math.round()
不会修改您的变量,因为将值传递给函数的double
(比较 all-by-value 与 call-by-reference)。
To round your value use四舍五入你的价值使用
a = Math.round(a);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.