# Thread: using % with doubles plz explain

1. Member
Join Date
Mar 2014
Posts
2
Rep Power
0

## using % with doubles plz explain

i got my self a learning java for dummies book manged to keep up till i hit this and its corsning me a head ache

Java Code:
```public class Test
{

public static void main(String[] args)
{

double x = 5.5, y = 2.0;

double q = x / y;
double w = x % y;
System.out.println(q +"     " + w);

}
}```
outputs 2.75 and 1.5
Plz explain where the hell 1.5 coming from i going to end up kicking myself for this i know but someone plz put some light on this
Last edited by zazarath; 03-10-2014 at 01:18 AM.

2. Senior Member
Join Date
Jan 2013
Posts
168
Rep Power
5

## Re: using % with doubles plz explain

The % is called modulus. It basically stands for remainder. So, when you do 5.5 % 2.0 it finds the remainder. 5.5 / 2 = 2 R 1.5, which has a remainder of 1.5. I hope this helps.

3. Member
Join Date
Mar 2014
Posts
2
Rep Power
0

## Re: using % with doubles plz explain

Originally Posted by pj6444
The % is called modulus. It basically stands for remainder. So, when you do 5.5 % 2.0 it finds the remainder. 5.5 / 2 = 2 R 1.5, which has a remainder of 1.5. I hope this helps.
soo basically your says it dose 5.5 - 2 = 3.5, 3.5 - 2 = 1.5 , cant take 2 from 1.5 so stops

yup kicking myself

also tyvm for clearing that up for me (stay tuned for more blonde moments as i am only on page 121 /833)
Last edited by zazarath; 03-10-2014 at 11:28 AM.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•