Force Python calculation in double -


i want print double in python. doesn't work, , don't know why.

my code:

test = 3000 / (1500 * 2000) print str(test) 

i 0 , not 0.001 if following:

test = 3000 / (1500 * 2000) print '%.10f' % test 

i 0.000000000 , not 0.001.

how tell python should double?

in python 2.x need convert @ least 1 of operands float, integer division results in truncated output in python 2.x:

>>> 3000 / (1500 * 2000) 0 >>> 3000.0 / (1500 * 2000) # or use float(3000) 0.001 >>> float(3000) / (1500 * 2000) 0.001 

or can import division of python 3.x in python 2.x, integer division results in true division:

>>> __future__ import division >>> 3000.0 / (1500 * 2000) 0.001 

note affect division in whole module.


Comments

Popular posts from this blog

c++ - Function signature as a function template parameter -

algorithm - What are some ways to combine a number of (potentially incompatible) sorted sub-sets of a total set into a (partial) ordering of the total set? -

How to call a javascript function after the page loads with a chrome extension? -