user904976
user904976

Reputation:

Floating point conversion

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

Answers (3)

hamon
hamon

Reputation: 1016

Maybe this helps

floatingpoint=float(str(i)+'.'+str(j))

Edit:

>>> float('%d.%d' % (i,j))
1.9

Upvotes: 3

Burhan Khalid
Burhan Khalid

Reputation: 174614

Not exactly.

>>> float(1+9*0.11)
1.99
>>> 1+9 * 0.1
1.8999999999999999

Upvotes: 1

Some programmer dude
Some programmer dude

Reputation: 409136

How about something like

>>> i = 1
>>> j = 9
>>> i + j / 10.0
1.8999999999999999

Upvotes: 1

Related Questions