In order to forcefully achieve both your desired outputs with the same f-string expression, you could apply some kung-fu like
i = 123
f"{i:.{3*isinstance(i, float)}f}"
# '123'
i = 123.0
f"{i:.{3*isinstance(i, float)}f}"
# '123.000'
But this won't improve your code in terms of readability. There's no harm in being more explicit.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…