• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Modulus problem

 
Nancy Antony
Ranch Hand
Posts: 145
Java Linux Oracle
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
System.out.println(-9+"%"+-7+"="+-9%-7); // result -2

System.out.println(-7.6+"%"+-2.9+"="+7.6%2.9);// 1.7999999999999998

double d=-7.6;
double e=-2.9;
double f=d%e;
System.out.println(d+"%"+e+"="+f);//-1.7999999999999998

I understand that sign of result is of left operand, but when both operands are negative real numbers, result is +ve. Why?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic