'what can i use instead of float or int if i want to show the zeros after point like number = 1.200

**i am adding two number with point **

number = float(str(num1)+"."+str(num2))

i am using them as index so when num1 = 1 and num2 = 200 it returns number = 1.2 instead I need number = 1.200 how can I do that



Solution 1:[1]

Here is simpler approach:

number = 1.2
print(number)
print(type(number))

number_of_zeros = 3
number_B = str(number) + "0" * number_of_zeros
print(number_B)
print(type(number_B))

number_C = format(number, f".{number_of_zeros+1}f")
print(number_C)
print(type(number_C))

Output:

1.2
<class 'float'>
1.2000
<class 'str'>
1.2000
<class 'str'>

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 Matúš Staš