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