1. Brief Introduction
To put it simply, convert the finite-cycle decimal places and the infinite-loop decimal places into the fractional form. For example:
0.9 = 9/10
0.333 (3) = 1/3, with parentheses representing the cyclic section.
2. Ideas
The method in the book is case-based discussion.
First, it is a finite repeating decimal point, such as 123.456. The integer part 123 is needless to say. It is mainly the decimal part 0.456, which is directly converted to 456/1000, and then the least major factor is eliminated.
The second is infinite cyclic decimal places, such as 123.4 (56), and the integer part 123 does not need to be solved, mainly the circular decimal part 0.4 (56 ), first, split the fractional part into two parts: Non-cyclic and loop. Note that the non-cyclic part, such as before the cyclic part (this is obvious), is 0.4 + 0.0 (56 ), the non-cyclic part 0.4 is directly converted to 4/10, and the processing of 0.0 (56) needs to be reduced by the recursive formula: 0.0 (56) * 100 = 5.6 (56) = 5.6 + 0.0 (56), 0.0 (56) = 5.6/99 = 56/990. The process of deriving a circular section is to multiply the circular section by the number of digits of the previous circular section, that is, for (56), multiply by 100, for (456) Multiply by 1000, after multiply, the circular section on both sides of the equation can be decomposed by means of formulas, and a circular Section is proposed and calculated.
This is basically the case. For the solution of the most common factor, the next section, that is, section 2.7, will discuss this issue. In general, the division of the moving phase is enough.
3. Code
Omitted.
4. Reference
The beauty of programming, section 2.6, precise expression of floating point numbers.