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

Perl - how to grep a block of text from a file -

delphi - How to remove all the grips on a coolbar if I have several coolbands? -

javascript - Animating array of divs; only the final element is modified -