Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
Solved

# convert double to integer

Posted on 2006-11-30
Medium Priority
824 Views
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
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
1 Comment

LVL 12

Accepted Solution

enachemc earned 160 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

Question has a verified solution.

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

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…
In this post we will learn how to make Android Gesture Tutorial and give different functionality whenever a user Touch or Scroll android screen.
This tutorial covers a step-by-step guide to install VisualVM launcher in eclipse.
This tutorial explains how to use the VisualVM tool for the Java platform application. This video goes into detail on the Threads, Sampler, and Profiler tabs.
###### Suggested Courses
Course of the Month6 days, 9 hours left to enroll