Skip to content

Instantly share code, notes, and snippets.

@paolorotolo
Last active February 2, 2016 18:37
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save paolorotolo/8a91f1772a037fd21310 to your computer and use it in GitHub Desktop.
Save paolorotolo/8a91f1772a037fd21310 to your computer and use it in GitHub Desktop.
Glucose Conversion tools in Java
import java.math.BigDecimal;
import java.math.RoundingMode;
public class GlucoseConverter {
public class GlucoseConverter {
public int glucoseToMgDl(double mmolL){
// Mg/dL = mmol/L * 18
double converted = mmolL * 18;
return (int) converted;
}
public double glucoseToMmolL(double mgDl){
return round(mgDl / 18.0, 1);
}
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();
}
public double glucoseToA1C(int mgDl){
// A1C = (Average glucose + 46.7) / 28.7
return (mgDl+46.7)/28.7;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment