How to round off numbers in an array [duplicate]?

Total Post:46

 1286  View(s)
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. Post:101

    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