0

I want to print a float value but if the value has no decimal (1.0, 2.0 etc, etc) I want to either remove the .0 part or convert it into an int so it removes the .0 anyway. Just for visual effect.

output:

You started with: 1.0

Wanted output:

You started with: 1

Scottish
  • 7
  • 4
  • Specifically the second answer, and in this instance, try `print("You started with: {number:g}".format(number=1.0))` – metatoaster Oct 07 '19 at 01:46

1 Answers1

0

you can check if the number is a whole number or not

number = 1.5
if number.is_integer():
    number = int(number)

print(number)
Rajith Thennakoon
  • 3,975
  • 2
  • 14
  • 24