Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Convert double to int

Posted on 2011-02-28
5
Medium Priority
?
620 Views
Last Modified: 2012-06-21
Please advice how to convert:
double marginUse = usedMargin / cashOutstanding * 100;
to int margin?
0
Comment
Question by:gbcbr
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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 500 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

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

Question has a verified solution.

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

For beginner Java programmers or at least those new to the Eclipse IDE, the following tutorial will show some (four) ways in which you can import your Java projects to your Eclipse workbench. Introduction While learning Java can be done with…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
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…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.
Suggested Courses

604 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