/*********************************************************************
* 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 you need to evaluate the results in a precise way, you want to get the floating-point value after the operation, then how to handle it?
1, modified dividend value for the form of a decimal point can be a floating-point value, this method in the case of dividend prior knowledge to be effective, and this situation means that the value of the divisor is written dead, fixed, in most cases is not feasible;
2, before the division operation to import a real division module, you can divide two integers when the result of floating point,
From __future__ Import Division
The following is the result 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
A method of dividing two integers in python to get the value of a floating-point number