AndroidAPS/app/src/main/java/info/nightscout/utils/DecimalFormatter.java

60 lines
1.8 KiB
Java
Raw Normal View History

2016-07-11 17:49:09 +02:00
package info.nightscout.utils;
import java.text.DecimalFormat;
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-04-09 19:52:01 +02:00
public static String to3Decimal(double value, String unit) {
return format3dec.format(value) + unit;
}
public static String toPumpSupportedBolus(double value) {
return ConfigBuilderPlugin.getActivePump().getPumpDescription().bolusStep <= 0.01
? to2Decimal(value)
: to1Decimal(value);
}
public static DecimalFormat pumpSupportedBolusFormat() {
return ConfigBuilderPlugin.getActivePump().getPumpDescription().bolusStep <= 0.01
? new DecimalFormat("0.00")
: new DecimalFormat("0.0");
}
2016-07-11 17:49:09 +02:00
}