How to get the floating point value after dividing two integers in python

Source: Internet
Author: User

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


Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.