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
  • Last Modified:

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
Asked:
jfuer102
1 Solution
 
yongsingCommented:
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
 
LeoleoCommented:
Maybe u can try this

double a=11111.622222;
Long b=new Long(Math.round(a));
int c=b.intValue() ;
0
 
LeoleoCommented:
Maybe u can try this

double a=11111.622222;
Long b=new Long(Math.round(a));
int c=b.intValue() ;
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
sciuriwareCommented:
I dislike the title of this question.
;JOOP!
0
 
yongsingCommented:
>> 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
 
Mayank SAssociate Director - Product EngineeringCommented:
Leoleois correct - try using the intValue () method which the Long class defines.

Mayank.
0

Featured Post

Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

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