Convert double to int

Posted on 2011-02-28
Last Modified: 2012-06-21
Please advice how to convert:
double marginUse = usedMargin / cashOutstanding * 100;
to int margin?
Question by:gbcbr
LVL 10

Expert Comment

ID: 35000852
    //use intValue method of Double class to convert it into int type.    int i = dObj.intValue();    System.out.println(i);
LVL 47

Accepted Solution

for_yan earned 125 total points
ID: 35000863
double marginUse = usedMargin / cashOutstanding * 100;

int intMargin = (int) (marginUse + 0.5);

that'll even round the number
LVL 10

Expert Comment

ID: 35000864
so in your case....

double marginUse = usedMargin / cashOutstanding * 100;
int i = dObj.intValue(marginUse);    
LVL 26

Expert Comment

ID: 35000892
int margin = ( int )margin ;

Author Closing Comment

ID: 35001003
simple and accurate.
Thank you

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Starting to learn JAVA, 7 59
Java and GPO 11 71
eclipse argument 14 53
servlet filter example 37 43
After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Introduction Java can be integrated with native programs using an interface called JNI(Java Native Interface). Native programs are programs which can directly run on the processor. JNI is simply a naming and calling convention so that the JVM (Java…
Viewers learn how to read error messages and identify possible mistakes that could cause hours of frustration. Coding is as much about debugging your code as it is about writing it. Define Error Message: Line Numbers: Type of Error: Break Down…
Viewers will learn about the regular for loop in Java and how to use it. Definition: Break the for loop down into 3 parts: Syntax when using for loops: Example using a for loop:

920 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now