Solved

Convert double to int

Posted on 2011-02-28
5
600 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 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

Industry Leaders: 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!

Question has a verified solution.

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

Java had always been an easily readable and understandable language.  Some relatively recent changes in the language seem to be changing this pretty fast, and anyone that had not seen any Java code for the last 5 years will possibly have issues unde…
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…
Viewers will learn about the different types of variables in Java and how to declare them. Decide the type of variable desired: Put the keyword corresponding to the type of variable in front of the variable name: Use the equal sign to assign a v…
This tutorial covers a practical example of lazy loading technique and early loading technique in a Singleton Design Pattern.

735 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