Truncating a number in the range [3.0, 4.0) returns the number 3
So, an easy way to truncate a positive value is to simply subtract 0.5 from it and then round it.
In simplest terms, truncation means to chop off the decimal portion of a number. This means:
The algorithm of subtracting 0.5 from a value and then rounding it (which truncates a positive number) actually has so many uses that Java has been nice enough to include a method in its standard library that will do it for you.
Note that when you subtract 0.5, you actually write it as 0.5f. This is because Java treats any decimal constant you write into your code as type double by default, and you must include a trailing 'f' if you wish the number to be treated as type float.
The round method is a static method in the class Math. Therefore, anytime you wish to call that method, the method name must be proceeded by the class name (ie: Math.round) Check the Java Class Documentation to see what type of values Math.round will accept as an argument and what types of values it will return.
If the number does need to be rounded, look at the third digit after the decimal. If that digit is greater than or equal to five, add 0.01 to the number you are rounding. If the digit is less than or equal to four, do nothing. Finally, erase everything after the second digit after the decimal.