Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 236

# Simple Question, 911!!!!!!

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
jfuer102
1 Solution

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

Commented:
Maybe u can try this

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

Commented:
Maybe u can try this

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

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

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

Associate Director - Product EngineeringCommented:
Leoleois correct - try using the intValue () method which the Long class defines.

Mayank.
0

## Featured Post

Tackle projects and never again get stuck behind a technical roadblock.