Home > Mobile >  Display result with 2 decimal points, without 0 at the end
Display result with 2 decimal points, without 0 at the end

Time:11-03

currently i get display: cup's to litre 0.30 but it needs to be 0.3

there is different unit conversion at the exercise, which need to be displayed with 2 decimal points

This is the code i have

tilavuus = float(input("Anna muunnettava tilavuus desimaalilukuna: "))

Cup_to_litra = tilavuus*0.24

print(f"Cup't muutettuina litroiksi: {Cup_to_litra:.2f}")
print()

Display: Cup't muutettuina litroiksi: 0.30

CodePudding user response:

Try using f"Cup't muutettuina litroiksi: {Cup_to_litra:.2g}"

  • Related