You can cast to float by doing c = a / float(b)
. If the numerator or denominator is a float, then the result will be also.
A caveat: as commenters have pointed out, this won’t work if b
might be something other than an integer or floating-point number (or a string representing one). If you might be dealing with other types (such as complex numbers) you’ll need to either check for those or use a different method.