Python is the correct method for Division operations on decimals.

Source: Internet
Author: User

Python is the correct method for Division operations on decimals.

Calculate a formula
Copy codeThe Code is as follows:
A = 1
B = 2
C = 3
 
Print c * (a/B)

The running result is always 0. After repeated check and splitting, it is found that in Python, the first integer can only be an integer.
That is, the result of dividing a by B is always 0. You only need to change the number of a or B to a floating point number.
Copy codeThe Code is as follows:
A = 1
B = 2
C = 3
 
Print c * (a/float (B ))
Print c * (float (a)/B)

In this way, the correct result of Division B can be accurately calculated. Of course, if a is larger than B, and float is not required.
For example:
Copy codeThe Code is as follows:
A = 1
B = 2
C = 3
 
Print c/a #3
Print c/B #1
Print c/float (B) #1.5


What is the method for the fourth-grade fractional multiplication and division operation?

The Operation Sequence of fractional multiplication and division is the same as that of integer multiplication and division.
The fractional multiplication calculation method is as follows: Calculate the integer multiplication method first, obtain the product, and check that there are several decimal places in the two factors, the number of digits from right to left in the multiplication product, with the decimal point.
The fractional Division calculation method is as follows: first convert the divisor to an integer Based on the constant nature of the quotient, and then perform the division by integer, note that the decimal point of the quotient must be aligned with the decimal point of the dividend.

What is the fractional division method?

The Division Principle of the decimal number is: the divisor and the divisor expand or contract the same multiple at the same time, and the quotient remains unchanged. The division of decimal places is calculated using the division of decimal places. The Division of decimal places is first moved to the decimal point (integer ); 0.756 bytes 0.18 = 75.6 bytes 18 = 4.2. The decimal point of the divisor is shifted to the right, and the decimal point of the divisor is also shifted to the right (a few digits). (if the number of digits is not enough, use "0" at the end of the divisor ); then it is calculated based on the fractional division of the divisor (integer. 3.3 running 0. 75 = 33 0 running 75 = 4.4. I hope you will be satisfied with the detailed and correct answers. If you have any questions, please ask. Thank you!
Please accept

Related Article

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.