Add double rounding helper

This commit is contained in:
Jamorham 2018-01-26 22:26:29 +00:00
parent 0966bea1e8
commit 3150e7d00f
No known key found for this signature in database
GPG key ID: 0BC5C3E0AAD64DF9
2 changed files with 8 additions and 1 deletions

View file

@ -7,6 +7,8 @@ import android.os.Handler;
import android.os.PowerManager;
import android.util.Log;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.text.DecimalFormat;
import java.text.DecimalFormatSymbols;
import java.util.HashMap;
@ -155,5 +157,11 @@ public class Helpers {
return niceTimeScalar(t).replaceFirst("^1 ", "");
}
public static double roundDouble(double value, int places) {
if (places < 0) throw new IllegalArgumentException("Invalid decimal places");
BigDecimal bd = new BigDecimal(value);
bd = bd.setScale(places, RoundingMode.HALF_UP);
return bd.doubleValue();
}
}

View file

@ -1,5 +1,4 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/insightstatusmasterlayout"
android:layout_width="match_parent"