What should I pay attention to when performing decimal operations ?, Decimal operation

Source: Internet
Author: User

What should I pay attention to when performing decimal operations ?, Decimal operation

1. 0.1 + 0.2 = 0.3 in daily life. This is not the case in computer. Why?

We all know that computer types have data ranges. The integer int range is about 2.1 billion, and the decimal type also has a range, but even if the Integer Range is 0.1 ~ Before 0.2, how many decimal places do you have?Infinite !!!

So how does a limited range represent infinite data? It means you can't store only one infinitely close number.

In addition, we all know that all data in a computer is binary. 0.5 is the power of-1 in 2, and 0.25 is the power of-2 in 2. It also explains why it cannot express all decimals.

In this way, you will understand the following example:Why is the sum of 100 and 0.1 not equal to 10?.

 

Because the computer is an infinitely close number to 0.1 to represent 0.1, so a number with an error participates in the calculation, the more error involved, the greater the error.

2. In the above case, how can we handle the decimal point operation in finance?

In case of decimal places, it is first expanded to an integer, and the result is calculated, and then divided by the multiple of the expansion. See

 

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.