-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
  • 2
  • 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
  • 822,522
  • 95
  • 1,334
  • 1,252
Mitiku
  • 5,337
  • 3
  • 18
  • 35
-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