Home > DeveloperSection > Forums > How to round off numbers in an array [duplicate]?
Allen Scott

Total Post:46

Posted on    October-29-2014 12:17 AM

 Java Java 

 1 Reply(s)
 896  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.

Pravesh Singh
Pravesh Singh

Total Post:101

Posted on    October-29-2014 12:19 AM

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));




Don't want to miss updates? Please click the below button!

Follow MindStick