ViewPager 指针四舍五入取整

This commit is contained in:
kehaoyuan
2017-10-11 15:34:12 +08:00
parent c5deb87c23
commit 02108b3273
8 changed files with 29 additions and 12 deletions

View File

@ -1,5 +1,6 @@
package com.gh.common.util;
import java.math.BigDecimal;
import java.util.Random;
/**
@ -41,4 +42,13 @@ public class RandomUtils {
return random.nextInt(size);
}
/**
* 四舍五入取整
* @return
*/
public static int getInt(double d) {
BigDecimal bigDecimal = new BigDecimal(d).setScale(0, BigDecimal.ROUND_HALF_UP);
return bigDecimal.intValue();
}
}