-3

Let's say I have a variable called a that is an integer, but I want the variable result to be a floating point. What should I use to accomplish this? I have used the round function but it didn't give expected output.

Expected Output:

 a=56
 result =function(a)
 result = 56.00
user123456789
  • 45
  • 1
  • 11

2 Answers2

2

Python has built in function for converting integer to float.

result = float(a)

In order to print with 2 decimal points you can do like this

print("%.2f" % a)
56.00
jezrael
  • 729,927
  • 78
  • 1,141
  • 1,090
Mitiku
  • 4,929
  • 3
  • 16
  • 33
-1

Cast float to integer number as below. for example.

a = 56
b = float(a)
print(print("%.2f" % b))
# ans will be 56.00
Chintak
  • 61
  • 5