/*********************************************************************
* Author:samson
* date:09/19/2014
* Test Platform:
* Linux Ubuntu 3.2.0-58-generic-pae
* GNU Bash, version 4.2.39
* *******************************************************************/
When you divide two integers in Python, by default it is only possible to get the value of an integer, and when it is necessary to make a precise evaluation of the results obtained, we want to get the floating-point value after the operation, so how to handle it?
1, change dividend value for the form with a decimal point can be obtained floating point value, such method in the case of dividend beforehand know the ability to use effective. This means that the value of the divisor is written dead, fixed, and in most cases is not feasible;
2, before the division operation to import a real division of the module, you can divide two integers when the result of floating point,
From __future__ Import Division
Here are the results of the test:
[Email protected]:~$ python
Python 2.7.4 (default, Sep 26 2013, 03:20:56)
[GCC 4.7.3] on linux2
Type "Help", "copyright", "credits" or "license" for more information.
>>> 244158112/1024
238435
# # #注意以上的运算结果为整数
# # #导入实除法模块后的结果为浮点数
>>> from __future__ Import Division
>>> 244158112/1024
238435.65625
>>> 244158112/1024/1024
232.84732055664062
Copyright notice: This article blog original article. Blogs, without consent, may not be reproduced.
Python two integers and floating-point methods to get values