java - BSA calculation results me Zero -
public static int calculatebsa(double height, double grams) { double weightforbmi = convertgramstopounds(grams); return (int) math.sqrt(((convertcentimetertoinches(height) * weightforbmi) / 3131)); }
here code converting centimeter inches , grams pounds.
private static double convertcentimetertoinches(double height) { return (math.round((height / 2.54) * 100) / 100); } public static int convertgramstopounds(double grams) { double gramstopoundunit = .00220462262; double pounds = (grams * gramstopoundunit); return (int)(math.round(pounds * 100) / 100); }
bsa calculation results me zero
. doing math.sqrt rightly inside bsa.
if call
calculatebsa(1e4, 1e4)
it returns 5. relative small values of grams convertgramstopounds(double grams) returns 0 because casted int. similar happens calculatebsa , convertcentimetertoinches methods. if can accept double values 1 can modify code as:
public double calculatebsa(double height, double grams) { double weightforbmi = convertgramstopounds(grams); return math.sqrt(((convertcentimetertoinches(height) * weightforbmi) / 3131)); } private double convertcentimetertoinches(double height) { return (height / 2.54); } public double convertgramstopounds(double grams) { double gramstopoundunit = .00220462262; double pounds = (grams * gramstopoundunit); return pounds; }