Skip to content

Instantly share code, notes, and snippets.

@f3r
Created November 15, 2014 10:48
Show Gist options
  • Save f3r/f0e4b49cf47cdcd1c55b to your computer and use it in GitHub Desktop.
Save f3r/f0e4b49cf47cdcd1c55b to your computer and use it in GitHub Desktop.
bmi calculator
cal_bmi = (weight_kg, height_cm) ->
height_m = height_cm/100
bmi = weight_kg / (height_m * height_m)
f_bmi = Math.floor(bmi)
diff = Math.round((bmi - f_bmi) * 10)
if diff == 10 # Need to bump up the whole thing instead
f_bmi += 1
diff = 0
return "#{f_bmi}.#{diff}"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment