Add MUtil.round()

This commit is contained in:
Olof Larsson 2015-02-23 15:32:39 +01:00
parent 5430af6567
commit ee1f4cf9c9

View File

@ -1,6 +1,8 @@
package com.massivecraft.massivecore.util; package com.massivecraft.massivecore.util;
import java.lang.reflect.Method; import java.lang.reflect.Method;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.net.InetSocketAddress; import java.net.InetSocketAddress;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -1347,6 +1349,15 @@ public class MUtil
return ret; return ret;
} }
public static double round(double value, int places)
{
if (places < 0) throw new IllegalArgumentException();
BigDecimal bd = new BigDecimal(value);
bd = bd.setScale(places, RoundingMode.HALF_UP);
return bd.doubleValue();
}
// -------------------------------------------- // // -------------------------------------------- //
// EXTRACTION // EXTRACTION
// -------------------------------------------- // // -------------------------------------------- //