?
Solved

Simple Question, 911!!!!!!

Posted on 2003-03-05
6
Medium Priority
?
227 Views
Last Modified: 2010-08-05
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
Comment
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
  • Learn & ask questions
6 Comments
 
LVL 9

Expert Comment

by:yongsing
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

by:Leoleo
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

by:Leoleo
ID: 8077290
Maybe u can try this

double a=11111.622222;
Long b=new Long(Math.round(a));
int c=b.intValue() ;
0
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
LVL 24

Expert Comment

by:sciuriware
ID: 8078120
I dislike the title of this question.
;JOOP!
0
 
LVL 9

Accepted Solution

by:
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

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

Mayank.
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

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

764 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question