Solved

convert double to integer

Posted on 2006-11-30
1
810 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

U.S. Department of Agriculture and Acronis Access

With the new era of mobile computing, smartphones and tablets, wireless communications and cloud services, the USDA sought to take advantage of a mobilized workforce and the blurring lines between personal and corporate computing resources.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Java - Why doesn't this JFrame work 3 60
Java Loop 6 62
tomcat administrtor 12 49
JavaFX TableView not displaying correctly 3 20
INTRODUCTION Working with files is a moderately common task in Java.  For most projects hard coding the file names, using parameters in configuration files, or using command-line arguments is sufficient.   However, when your application has vi…
Introduction This article is the second of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article covers the basic installation and configuration of the test automation tools used by…
Viewers will learn about if statements in Java and their use The if statement: The condition required to create an if statement: Variations of if statements: An example using if statements:
This video teaches viewers about errors in exception handling.

831 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