Solved

Convert double to int

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

Threat Intelligence Starter Resources

Integrating threat intelligence can be challenging, and not all companies are ready. These resources can help you build awareness and prepare for defense.

Join & Write a Comment

For customizing the look of your lightweight component and making it look lucid like it was made of glass. Or: how to make your component more Apple-ish ;) This tip assumes your component to be of rectangular shape and completely opaque. (COD…
By the end of 1980s, object oriented programming using languages like C++, Simula69 and ObjectPascal gained momentum. It looked like programmers finally found the perfect language. C++ successfully combined the object oriented principles of Simula w…
Viewers learn about the third conditional statement “else if” and use it in an example program. Then additional information about conditional statements is provided, covering the topic thoroughly. Viewers learn about the third conditional statement …
This video teaches viewers about errors in exception handling.

706 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

21 Experts available now in Live!

Get 1:1 Help Now