How to get the floating point value after dividing two integers in python
/*************************************** ******************************
* Author: Samson
* Date: 09/19/2014
* Test platform:
* Linux ubuntu 3.2.0-58-generic-pae
* GNU bash, version 4.2.39
**************************************** ****************************/
When two integers are separated in python, only the values of integers can be obtained by default. When the division result needs to be accurately evaluated, how can I get the floating point value after the operation?
1. Modify the divisor value to a decimal point to obtain the floating point value. This method is valid only when the divisor is known in advance, in this case, it means that the divisor value is writable and fixed. In most cases, it is not feasible;
2. Import a real division module before Division to obtain the floating point result when two integers are involved in Division,
From _ future _ import division
The test results are as follows:
Ufo @ ufo :~ $ 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
#### Note that the preceding calculation result is an integer.
#### The result after the real division module is imported is a floating point number.
>>> From _ future _ import division
>>> 244158112/1024
238435.65625
>>> 244158112/1024/1024
232.84732055664062