Reputation:
How can I create a floating point decimal from the two variables who are integers
i=1
j=9
is there anyway to combine these two and get the floating point decimal 1.9?
Upvotes: 1
Views: 218
Reputation: 1016
Maybe this helps
floatingpoint=float(str(i)+'.'+str(j))
Edit:
>>> float('%d.%d' % (i,j))
1.9
Upvotes: 3
Reputation: 174614
Not exactly.
>>> float(1+9*0.11)
1.99
>>> 1+9 * 0.1
1.8999999999999999
Upvotes: 1
Reputation: 409136
How about something like
>>> i = 1
>>> j = 9
>>> i + j / 10.0
1.8999999999999999
Upvotes: 1