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; } 

Popular posts from this blog

How to calculate SNR of signals in MATLAB? -

c# - Attempting to upload to FTP: System.Net.WebException: System error -

ios - UISlider customization: how to properly add shadow to custom knob image -