Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

rounding a double to an int

Status
Not open for further replies.

mluken

Programmer
Dec 31, 2003
54
US
What is the best way to round a double to an int? Math.round doesn't return an int when a double is passed in - only a long. So if I want to use Math.round, I actually have to do this:

int myInt = Math.round(Math.round(myDouble));

Kind of redundant? Thoughts?
 
Your choices are :

Code:
double d = 15.45465;

int i = Math.round((float)d);
// or
int i2 = (int)Math.round(d);

PS, this forum is for questions regarding J2EE. In the future, for questions concering J2SE, please use forum269 .

--------------------------------------------------
Free Database Connection Pooling Software
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top