[JAVA] Rounding Help

PureOwnage

Minecraft Server OP, Inactive.
Reaction score
72
I just started some JAVA and I was hoping to learn how to round a float number to a integer (example: 27.92 -> 27) and how to round an number to the nearest evens place if the number is not even.
 

Ghan

Administrator - Servers are fun
Staff member
Reaction score
888
Math.round
Math.floor
Math.ceil

Round will round the number according to the standard rounding rules.
Floor will round the number down always.
Ceil will round the number up always.

Then you can cast the number to an int if necessary. For example:

float foo = 10.5;
float bar = Math.round(foo);
int foobar = (int) bar;
 
General chit-chat
Help Users
  • No one is chatting at the moment.

      The Helper Discord

      Members online

      Affiliates

      Hive Workshop NUON Dome World Editor Tutorials

      Network Sponsors

      Apex Steel Pipe - Buys and sells Steel Pipe.
      Top