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

Allen Scott

Total Post:46

Points:324
Posted by  Allen Scott
Java 
 1100  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));
     
       }
    }

      Modified On Apr-06-2018 01:29:30 AM

Answer

NEWSLETTER

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