Last active
February 2, 2016 18:37
-
-
Save paolorotolo/8a91f1772a037fd21310 to your computer and use it in GitHub Desktop.
Glucose Conversion tools in Java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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