Solved

convert double to integer

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say 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
Crystal Reports Licensing Questions 4 59
Java syntax, or is it Selenium 6 37
Eclipse with various Java releases 7 44
Eclipse for Java EE development 2 43
This was posted to the Netbeans forum a Feb, 2010 and I also sent it to Verisign. Who didn't help much in my struggles to get my application signed. ------------------------- Start The idea here is to target your cell phones with the correct…
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 …
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 …
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:

761 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