/** * @author lautturi.com * Java example: how to use math.round math.floor */ import java.util.*; public class Lautturi { public static void main(String[] args) { System.out.println(Math.floor(4.5)); System.out.println(Math.floor(-5.4)); System.out.println(Math.round(-5.4)); System.out.println(Math.floor(-5.5)); System.out.println(Math.round(-5.5)); System.out.println(Math.floor(5.4)); System.out.println(Math.floor(5.5)); System.out.println(Math.round(5.5)); System.out.println(Math.ceil(5.5)); System.out.println(Math.floor(5.57 * 10) / 10); } }
output:
4.0 -6.0 -5 -6.0 -5 5.0 5.0 6 6.0 5.5