Solved

Convert double to int

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

Expert Comment

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

http://www.java-examples.com/convert-java-double-numeric-primitive-data-types-example
0
 
LVL 47

Accepted Solution

by:
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
0
 
LVL 10

Expert Comment

by:GlobaLevel
ID: 35000864
so in your case....

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

Expert Comment

by:ksivananth
ID: 35000892
int margin = ( int )margin ;
0
 

Author Closing Comment

by:gbcbr
ID: 35001003
simple and accurate.
Thank you
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
split53 challenge 7 95
Checkbox and ListView in Android Layout 4 65
tomcat administrtor 12 46
jboss wildfly 10.1 10 80
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Basic understanding on "OO- Object Orientation" is needed for designing a logical solution to solve a problem. Basic OOAD is a prerequisite for a coder to ensure that they follow the basic design of OO. This would help developers to understand the b…
Video by: Michael
Viewers learn about how to reduce the potential repetitiveness of coding in main by developing methods to perform specific tasks for their program. Additionally, objects are introduced for the purpose of learning how to call methods in Java. Define …
This video teaches viewers about errors in exception handling.

808 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