Solved

convert double to integer

Posted on 2006-11-30
1
802 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
Comment Utility
           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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
Introduction This article is the first of three articles that explain why and how the Experts Exchange QA Team does test automation for our web site. This article explains our test automation goals. Then rationale is given for the tools we use to a…
Viewers learn about the scanner class in this video and are introduced to receiving user input for their programs. Additionally, objects, conditional statements, and loops are used to help reinforce the concepts. Introduce Scanner class: Importing…
This tutorial will introduce the viewer to VisualVM for the Java platform application. This video explains an example program and covers the Overview, Monitor, and Heap Dump tabs.

744 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

12 Experts available now in Live!

Get 1:1 Help Now