在 Python 中将 BMI 舍入到 2 位数
Round BMI to 2 digits in Python
我正在尝试对作为浮点值的 bmi 值进行舍入 0.0027041644131963224
。我希望我的值看起来像这样 27.00
.
我试过这样四舍五入:
bmiCalc = profile.weight / (profile.height*profile.height)
bmi = round(bmiCalc, 2)
我想你忘了将高度转换为米?试试这个:
bmiCalc = profile.weight / (profile.height*profile.height / (100**2))
bmi = round(bmiCalc,2)
(对于您的示例,这将输出 27.04
,但您可以在 round()
函数中调整小数位)
我正在尝试对作为浮点值的 bmi 值进行舍入 0.0027041644131963224
。我希望我的值看起来像这样 27.00
.
我试过这样四舍五入:
bmiCalc = profile.weight / (profile.height*profile.height)
bmi = round(bmiCalc, 2)
我想你忘了将高度转换为米?试试这个:
bmiCalc = profile.weight / (profile.height*profile.height / (100**2))
bmi = round(bmiCalc,2)
(对于您的示例,这将输出 27.04
,但您可以在 round()
函数中调整小数位)