0%
运算
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30
|
public class MathTest { @Test public void test(){ double result = Math.sqrt(4); System.out.println("sqrt result:" + result); result = Math.pow(4, 2); System.out.println("pow result:" + result); int i = Math.floorMod(5, 2); System.out.println("i:" + i); long round = Math.round(1.5); System.out.println("round:" + round);
System.out.println("up:" + Math.ceil(4.000000001)); System.out.println("floor:" + Math.floor(4.99999)); } @Test public void leftMove(){ int result = 3 << 2; System.out.println("<<:" + result); } @Test public void rightMove(){ int result = 12 >> 2; System.out.println(">>:" + result); } }
|
大数:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31
|
public class BigDecimalTest { @Test public void test(){ System.out.println(1.1 + 2.2);
double a = 1.1; double b = 2.2;
BigDecimal bigDecimal = BigDecimal.valueOf(a); BigDecimal bigDecimal1 = BigDecimal.valueOf(b);
BigDecimal add = bigDecimal.add(bigDecimal1); System.out.println(add);
double value = bigDecimal.doubleValue();
int compare = Double.compare(1.1, 6.3); } }
|