'How do I add another 0 in my float output "$7.0" using format() in Python

def cash_converter():
        integer = input("enter an integer: ")  # Prompt user for integer input: 7
        sentence = "That is ${}".format(float(integer))
        print(sentence)

My Output:

enter an integer: 7

That is $7.0

Expected Output:

enter an integer: 7

That is $7.00



Solution 1:[1]

(:."number"f) will determine the number of deicimels.

Change

sentence = "That is ${}".format(float(integer))

to

sentence = "That is ${:.2f}".format(float(integer))

Solution 2:[2]

There are a few ways that you can do this the way that I would do it is like this

print(format(7, ",.2f"))

This will format the value to the 2 decimal place.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 hteza
Solution 2 ShadowGunn