Add MathUtil.java
Penambahan subrutin pembulatan nilai double
This commit is contained in:
parent
93cb7861df
commit
dc17e38d70
@ -0,0 +1,26 @@
|
|||||||
|
package com.jasamedika.medifirst2000.util;
|
||||||
|
|
||||||
|
import java.math.BigDecimal;
|
||||||
|
import java.math.RoundingMode;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @author salmanoe
|
||||||
|
* @since Dec 29, 2021
|
||||||
|
*/
|
||||||
|
public class MathUtil {
|
||||||
|
|
||||||
|
public MathUtil() {
|
||||||
|
super();
|
||||||
|
}
|
||||||
|
|
||||||
|
public static double round(double value, int places) {
|
||||||
|
if (places < 0)
|
||||||
|
throw new IllegalArgumentException();
|
||||||
|
|
||||||
|
BigDecimal bd = BigDecimal.valueOf(value);
|
||||||
|
bd = bd.setScale(places, RoundingMode.HALF_UP);
|
||||||
|
|
||||||
|
return bd.doubleValue();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user