There is some way in IronPython to force an expression containing integer values to evaluate as a floating point. For example, I would like the expression
1/3
estimated as
1./3.
with the result 0.333 ...
I need this to make a simple runtime expression calculator in a C # project using IronPython. I cannot get users to enter an expression with end decimal points.
You can force floating point division, like any of them, regardless of whether anything is imported from __future__:
__future__
print val1 / (val2 + 0.0) print (val1 + 0.0) / val2 print float(val1) / val2 print val1 / float(val2)
from __future__ import division print 1 / 3 print 1 // 3
, , , int s. float.
int
float
val1 = float(raw_input()) val2 = float(raw_input()) print val1/val2