Welcome! Log In Create A New Profile


Integer division

Posted by Ryan Botha 
Announcements Last Post
Announcement SoC Curricula 09/30/2017 01:08PM
Announcement Demarcation or scoping of examinations and assessment 02/13/2017 07:59AM
Announcement School of Computing Short Learning Programmes 11/24/2014 08:37AM
Announcement Unisa contact information 07/28/2011 01:28PM
Integer division
May 31, 2008 02:09PM
All i want to do is divide the numbers below, and display the result. How...?
Heres my code:

Double d1 = new Double(230 - ((41 / 275) * 190));
//I thought double so the decimals remain

int yValue = d1.intValue();
//round it off to an integer

//display on the screen

The screen output is ALWAYS 0. I understand that as integers (41/275) = 0, but why does that happen in double, and surely it should only round off at the end of the entire equation?

Help please!
Re: Integer division
May 31, 2008 06:07PM
Do worry, after a knap, the rearranging the order of variables...

230 - (41 * 190)/275;

seemed to work..
Re: Integer division
June 17, 2008 10:23AM
I have an idea,

Just add .0 to all your numbers. ex (230.0 - ((41.0 / 275.0) * 190.0)). 'Cause 41/275 is still integer division.

41 and 275 are integers.

You didn't say:

Double d1 = new Double(41);
Double d2 = new Double(275);
Double d3 = new Double(d1/d2):

Which is just toooooooo long.

Think the above will work(Not sure, sometimes get confused with syntax in different languages).
Sorry, only registered users may post in this forum.

Click here to login