简体   繁体   中英

Result of Math.round() is ignored

Why is it not working?I want to "odleglosc" is 2.2 not 2.214354356

在此处输入图片说明

Math.round(argument) returns a number that is rounded from the 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); Java will make the calculation and have no variable to assign it to, and gets thrown away.

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).

To round your value use

a = Math.round(a);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM