Solved

convert double to integer

Posted on 2006-11-30
1
805 Views
Last Modified: 2008-02-01
How to convert double to integer? and vice versa?

Or how to perform this opertion


I used to cast but I faced an error

If x is int and y is double

Then if I perform:

x = x * y;


gave me an error

possible loss of precision: double, required: int
0
Comment
Question by:javamate06
1 Comment
 
LVL 12

Accepted Solution

by:
enachemc earned 40 total points
ID: 18045411
           int x = 2;
            double y = 1;
            
            x = x * (int)y;
            x = (int)(x * y);

There is no error here (maybe a warning, but no error); Be careful, the two lines above are not equivalent. They might produce different results, depending on the value of y.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

After being asked a question last year, I went into one of my moods where I did some research and code just for the fun and learning of it all.  Subsequently, from this journey, I put together this article on "Range Searching Using Visual Basic.NET …
Java contains several comparison operators (e.g., <, <=, >, >=, ==, !=) that allow you to compare primitive values. However, these operators cannot be used to compare the contents of objects. Interface Comparable is used to allow objects of a cl…
Viewers learn about the “while” loop and how to utilize it correctly in Java. Additionally, viewers begin exploring how to include conditional statements within a while loop and avoid an endless loop. Define While Loop: Basic Example: Explanatio…
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…

932 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

10 Experts available now in Live!

Get 1:1 Help Now