HOW TO ROUND OFF NUMBERS IN AN ARRAY [DUPLICATE]?

Allen Scott

Total Post:46

Points:324
Posted by  Allen Scott
Java 
 925  View(s)
Ratings:
Rate this:
I cannot find any pattern rounding off doubles in an array. I am trying to make a program that will input a double like grades,money etc., and round it off in a whole number.
  1. Pravesh Singh

    Post:101

    Points:709
    Re: How to round off numbers in an array [duplicate]?

    Have you tried Math.round() ?


    import java.lang.*;

     

    public class MathDemo {

     

       public static void main(String[] args) {

     

          // get two float numbers

          float x = 1654.9874f;

          float y = -9765.134f;

     

          // find the closest int for these floats

          System.out.println("Math.round(" + x + ")=" + Math.round(x));

          System.out.println("Math.round(" + y + ")=" + Math.round(y));

     

       }

    }

Answer

NEWSLETTER

Enter your email address here always to be updated. We promise not to spam!