Solved

Simple Question, 911!!!!!!

Posted on 2003-03-05
Medium Priority
227 Views
Hello There.
I just need to round a double value.
I know I'm supposed to use Math.round, but...
what if I want an integer, not a long??
Casting doesn't appear to be a solution, can anyone help?? ASAP!

Thanks

JEan
0
Question by:jfuer102
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points

LVL 9

Expert Comment

ID: 8076820
There are two Math.round() methods. One accepts a float and returns an int. The other accepts a double and returns a long.

You can use the first one as follows:

int result = Math.round((float)doubleValue);
0

Expert Comment

ID: 8077251
Maybe u can try this

double a=11111.622222;
Long b=new Long(Math.round(a));
int c=b.intValue() ;
0

Expert Comment

ID: 8077290
Maybe u can try this

double a=11111.622222;
Long b=new Long(Math.round(a));
int c=b.intValue() ;
0

LVL 24

Expert Comment

ID: 8078120
I dislike the title of this question.
;JOOP!
0

LVL 9

Accepted Solution

yongsing earned 90 total points
ID: 8078183
>> Casting doesn't appear to be a solution

What are you going to do if the value is larger than what an integer can hold?

If you know that an integer will be enough to hold the value, than casting the long to integer would not be a problem at all.
0

LVL 30

Expert Comment

ID: 8087553
Leoleois correct - try using the intValue () method which the Long class defines.

Mayank.
0

Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done withâ€¦
Are you developing a Java application and want to create Excel Spreadsheets? You have come to the right place, this article will describe how you can create Excel Spreadsheets from a Java Application. For the purposes of this article, I will be uâ€¦
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
Suggested Courses
Course of the Month9 days, 1 hour left to enroll