2016-07-11 17:49:09 +02:00
|
|
|
package info.nightscout.utils;
|
|
|
|
|
|
|
|
import java.text.DecimalFormat;
|
|
|
|
|
2018-03-23 22:08:05 +01:00
|
|
|
import info.nightscout.androidaps.plugins.ConfigBuilder.ConfigBuilderPlugin;
|
|
|
|
|
2016-07-11 17:49:09 +02:00
|
|
|
/**
|
|
|
|
* Created by mike on 11.07.2016.
|
|
|
|
*/
|
|
|
|
public class DecimalFormatter {
|
|
|
|
private static DecimalFormat format0dec = new DecimalFormat("0");
|
|
|
|
private static DecimalFormat format1dec = new DecimalFormat("0.0");
|
|
|
|
private static DecimalFormat format2dec = new DecimalFormat("0.00");
|
|
|
|
private static DecimalFormat format3dec = new DecimalFormat("0.000");
|
|
|
|
|
|
|
|
public static String to0Decimal(double value) {
|
|
|
|
return format0dec.format(value);
|
|
|
|
}
|
|
|
|
|
2018-04-09 19:52:01 +02:00
|
|
|
public static String to0Decimal(double value, String unit) {
|
|
|
|
return format0dec.format(value) + unit;
|
|
|
|
}
|
|
|
|
|
2016-07-11 17:49:09 +02:00
|
|
|
public static String to1Decimal(double value) {
|
|
|
|
return format1dec.format(value);
|
|
|
|
}
|
|
|
|
|
2018-04-09 19:52:01 +02:00
|
|
|
public static String to1Decimal(double value, String unit) {
|
|
|
|
return format1dec.format(value) + unit;
|
|
|
|
}
|
|
|
|
|
2016-07-11 17:49:09 +02:00
|
|
|
public static String to2Decimal(double value) {
|
|
|
|
return format2dec.format(value);
|
|
|
|
}
|
|
|
|
|
2018-04-09 19:52:01 +02:00
|
|
|
public static String to2Decimal(double value, String unit) {
|
|
|
|
return format2dec.format(value) + unit;
|
|
|
|
}
|
|
|
|
|
2016-07-11 17:49:09 +02:00
|
|
|
public static String to3Decimal(double value) {
|
|
|
|
return format3dec.format(value);
|
|
|
|
}
|
2018-03-23 22:08:05 +01:00
|
|
|
|
2018-04-09 19:52:01 +02:00
|
|
|
public static String to3Decimal(double value, String unit) {
|
|
|
|
return format3dec.format(value) + unit;
|
|
|
|
}
|
|
|
|
|
2018-03-23 22:08:05 +01:00
|
|
|
public static String toPumpSupportedBolus(double value) {
|
2018-04-20 22:13:20 +02:00
|
|
|
return ConfigBuilderPlugin.getActivePump().getPumpDescription().bolusStep <= 0.05
|
2018-03-23 22:08:05 +01:00
|
|
|
? to2Decimal(value)
|
|
|
|
: to1Decimal(value);
|
|
|
|
}
|
|
|
|
|
|
|
|
public static DecimalFormat pumpSupportedBolusFormat() {
|
2018-04-20 22:13:20 +02:00
|
|
|
return ConfigBuilderPlugin.getActivePump().getPumpDescription().bolusStep <= 0.05
|
2018-03-23 22:08:05 +01:00
|
|
|
? new DecimalFormat("0.00")
|
|
|
|
: new DecimalFormat("0.0");
|
|
|
|
}
|
2016-07-11 17:49:09 +02:00
|
|
|
}
|