Round float and double numbers using Math.round - Java Language Basics

Java examples for Language Basics:Math

Description

Round float and double numbers using Math.round

Demo Code


public class Main {
 
  public static void main(String[] args) {
     System.out.println(Math.round(10f));
   // w  w w.j  a  v a 2 s. c o m
     System.out.println(Math.round(1.5f));
   
     System.out.println(Math.round(120.5f));
   
     System.out.println(Math.round(-129.4f));
   
     System.out.println(Math.round(-123.5f));
   
  }
}

Result


Related Tutorials