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

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

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
windows explorer path to command prompt 5 54
java jdbc batch example 8 41
Why my table column Id is not passed to java object? 4 44
null output 3 35
Introduction This article is the last of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers our test design approach and then goes through a simple test case example, how …
In this post we will learn how to connect and configure Android Device (Smartphone etc.) with Android Studio. After that we will run a simple Hello World Program.
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
Viewers will learn one way to get user input in Java. Introduce the Scanner object: Declare the variable that stores the user input: An example prompting the user for input: Methods you need to invoke in order to properly get  user input:

861 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