关于负数取模,参照
http://www.cnblogs.com/jasonkoo/articles/2213763.html
http://blog.newnius.com/mod-or-division-of-negative.html
小数取模,变成整数后计算即可。
public void test() {
byte b = 34;
byte a = 3;
int c = b % a;
System.out.println(b + "%" + a + "=" + c);
b = 34;
a = -3;
c = b % a;
System.out.println(b + "%" + a + "=" + c);
b = -34;
a = 3;
c = b % a;
System.out.println(b + "%" + a + "=" + c);
b = -34;
a = -3;
c = b % a;
System.out.println(b + "%" + a + "=" + c);
}
public void test2() {
double b = 3.4;
double a = 0.3;
double c = b % a;
System.out.println(b + "%" + a + "=" + c);
b = 3.4;
a = -0.3;
c = b % a;
System.out.println(b + "%" + a + "=" + c);
b = -3.4;
a = 0.3;
c = b % a;
System.out.println(b + "%" + a + "=" + c);
b = -3.4;
a = -0.3;
c = b % a;
System.out.println(b + "%" + a + "=" + c);
b = 3.4;
a = 0.3;
c = b / a;
System.out.println(b + "/" + a + "=" + c);
}
public void test3() {
float b = 3.4f;
float a = 0.3f;
float c = b % a;
System.out.println(b + "%" + a + "=" + c);
b = 3.4f;
a = -0.3f;
c = b % a;
System.out.println(b + "%" + a + "=" + c);
b = -3.4f;
a = 0.3f;
c = b % a;
System.out.println(b + "%" + a + "=" + c);
b = -3.4f;
a = -0.3f;
c = b % a;
System.out.println(b + "%" + a + "=" + c);
b = 3.4f;
a = 0.3f;
c = b / a;
System.out.println(b + "/" + a + "=" + c);
}
public void test4() {
double b = 3.24;
double a = 3;
double c = b % a;
System.out.println(b + "%" + a + "=" + c);
b = 6;
a = 3.5;
c = b % a;
System.out.println(b + "%" + a + "=" + c);
b = 3.24;
a = 0.3;
c = b % a;
System.out.println(b + "%" + a + "=" + c);
b = 3.24;
a = 0.03;
c = b % a;
System.out.println(b + "%" + a + "=" + c);
b = 32.4;
a = 3;
c = b % a;
System.out.println(b + "%" + a + "=" + c);
b = 324;
a = 3;
c = b % a;
System.out.println(b + "%" + a + "=" + c);
}
public void test5() {
long b = 324;
long a = 300;
long c = b % a;
System.out.println(b + "%" + a + "=" + c);
b = 60;
a = 35;
c = b % a;
System.out.println(b + "%" + a + "=" + c);
b = 34;
a = 3;
c = b % a;
System.out.println(b + "%" + a + "=" + c);
b = 324;
a = 30;
c = b % a;
System.out.println(b + "%" + a + "=" + c);
b = 324;
a = 3;
c = b % a;
System.out.println(b + "%" + a + "=" + c);
}
34%3=1
34%-3=1
-34%3=-1
-34%-3=-1
3.4%0.3=0.10000000000000003
3.4%-0.3=0.10000000000000003
-3.4%0.3=-0.10000000000000003
-3.4%-0.3=-0.10000000000000003
3.4/0.3=11.333333333333334
3.4%0.3=0.099999964
3.4%-0.3=0.099999964
-3.4%0.3=-0.099999964
-3.4%-0.3=-0.099999964
3.4/0.3=11.333333
3.24%3.0=0.2400000000000002
6.0%3.5=2.5
3.24%0.3=0.24000000000000032
3.24%0.03=3.3306690738754696E-16
32.4%3.0=2.3999999999999986
324.0%3.0=0.0
324%300=24
60%35=25
34%3=1
324%30=24
324%3=0