浮点精度
parent
d4ee477baa
commit
7f55f8cbc4
|
@ -105,6 +105,9 @@ public class MathUtils {
|
|||
return Math.round(num);
|
||||
}
|
||||
|
||||
public static long numRount(double num){
|
||||
return Math.round(num);
|
||||
}
|
||||
/**
|
||||
* 限置为 >=min <= max的值
|
||||
*
|
||||
|
@ -368,10 +371,36 @@ public class MathUtils {
|
|||
return result;
|
||||
}
|
||||
|
||||
/**
|
||||
*
|
||||
* to fix zsx
|
||||
* <li>
|
||||
* When a {@code double} must be used as a source for a
|
||||
* {@code BigDecimal}, note that this constructor provides an
|
||||
* exact conversion; it does not give the same result as
|
||||
* converting the {@code double} to a {@code String} using the
|
||||
* {@link Double#toString(double)} method and then using the
|
||||
* {@link #BigDecimal(String)} constructor. To get that result,
|
||||
* use the {@code static} {@link #valueOf(double)} method.
|
||||
* </ol>
|
||||
* @param d1
|
||||
* @param d2
|
||||
* @return
|
||||
*/
|
||||
public static double doubleAdd(double d1 ,double d2){
|
||||
BigDecimal b1 = new BigDecimal(Double.toString(d1));
|
||||
BigDecimal b2 = new BigDecimal(Double.toString(d2));
|
||||
BigDecimal b1 = new BigDecimal(String.valueOf(d1));
|
||||
BigDecimal b2 = new BigDecimal(String.valueOf(d2));
|
||||
return b1.add(b2).doubleValue();
|
||||
}
|
||||
|
||||
public static double doubleSubtract(double d1 ,double d2){
|
||||
BigDecimal b1 = new BigDecimal(String.valueOf(d1));
|
||||
BigDecimal b2 = new BigDecimal(String.valueOf(d2));
|
||||
return b1.subtract(b2).doubleValue();
|
||||
}
|
||||
|
||||
public static double floatToDouble(float f){
|
||||
return Double.parseDouble(Float.toString(f));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -448,7 +448,7 @@ public class ItemUtil {
|
|||
if (sRewardItem.getRandomMin() == sRewardItem.getRandomMax()) {
|
||||
itemNum = sRewardItem.getRandomMin();
|
||||
}else {
|
||||
itemNum = MathUtils.numRount(MathUtils.random(sRewardItem.getRandomMin(), sRewardItem.getRandomMax()) * sRewardItem.getGrowChance());
|
||||
itemNum =(int) MathUtils.numRount(MathUtils.random(sRewardItem.getRandomMin(), sRewardItem.getRandomMax()) * MathUtils.floatToDouble(sRewardItem.getGrowChance()));
|
||||
}
|
||||
|
||||
//权重加成 1等级权重加成
|
||||
|
@ -481,7 +481,7 @@ public class ItemUtil {
|
|||
private static void getMap(int itemId ,int itemNum, Map<Integer, Integer> itemMap,
|
||||
Map<Integer, Integer> cardMap,Map<Integer,Integer> equipMap ,Map<Integer,Integer> randomMap,float dropRatio) throws ErrorCodeException{
|
||||
Map<Integer, Integer> mapRe = getMapRe(itemId, itemMap, cardMap, equipMap, randomMap);
|
||||
putcountMap(itemId,MathUtils.numRount((itemNum * dropRatio)) , mapRe);
|
||||
putcountMap(itemId,(int)MathUtils.numRount((itemNum * MathUtils.floatToDouble(dropRatio))) , mapRe);
|
||||
}
|
||||
|
||||
public static Map<Integer, Integer> getMapRe(int itemId, Map<Integer, Integer> itemMap,
|
||||
|
|
Loading…
Reference in New Issue