# using % with doubles plz explain

• 03-10-2014, 01:09 AM
zazarath
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

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
• 03-10-2014, 01:51 AM
pj6444
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.
• 03-10-2014, 02:15 AM
zazarath
Re: using % with doubles plz explain
Quote:

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)