Monday 16 October 2017

How do I show decimal calculations in python?





When I do a division in Python/Pandas (e.g. 47/100) how do I show
the decimal value of the answer, because at the moment it just shows as
0?




Thanks in
advance.



Answer




If you're using python2.x, you need to
"floatify"1 one of your
numbers:



float(47)/100
47.0/100


As
python2.x will do integer division if both numbers in the division are
integers.




1floatify:
Forcing a number to be a float



No comments:

Post a Comment

php - file_get_contents shows unexpected output while reading a file

I want to output an inline jpg image as a base64 encoded string, however when I do this : $contents = file_get_contents($filename); print &q...