1. Using formatting (not recommended)123 >>> A ="%.30f"% (1/3)>>>a'0.333333333333333314829616256247'can be displayed, but inaccurate, the numbers that follow are often meaningless. 2. High precision using the decimal module, with GetContext123456789101112 >>> fromDecimalImport*>>>Print(GetContext ()) Context (Prec=28, Rounding=round_half_even, emin=-999999, emax=999999, Capitals=1, Clamp=0, flags=[], traps=[InvalidOperation, Divisionbyzero, Overflow])>>> GetContext (). Prec = 50>>> B = Decimal (1)/decimal (3)>>>Bdecimal ('0.33333333333333333333333333333333333333333333333333')>>> C = Decimal (1)/decimal (17)>>>Cdecimal ('0.058823529411764705882352941176470588235294117647059')>>>float (c)0.058823529411764705The default context precision is 28 bits, which can be set to 50 bits or higher. This way, when analyzing complex floating-point numbers, you can have a higher level of accuracy that you can control. Actually, you can keep an eye on the rounding in the context.The =round_half_even parameter. Round_half_even, when half, close to even.
Python defaults to 17 decimal places, but here's a question of what to do when our calculations need to use higher precision (more than 17 decimal places).