amount = 112.31
print(amount)
amount with 20 digits of precision to the right of the decimal point to see that the actual floating-point value in memory is not exactly 112.31—it’s only an approximation:print(f'{amount:.20f}')
Decimal, which uses a special coding scheme to solve the problem of to-the-penny precision. Decimal offers such capabilities.decimal module defines type Decimal and its capabilities. import to use capabilities from a module.from decimal import Decimal
Decimal from a string.principal = Decimal('1000.00')
principal
rate = Decimal('0.05')
rate
Decimals support the standard arithmetic operators and augmented assignments.x = Decimal('10.5')
y = Decimal('2')
x + y
x // y
x += y
x
Decimals and integers, but not between Decimals and floating-point numbers.Requirements statement:
A person invests $1000 in a savings account yielding 5% interest. Assuming that the person leaves all interest on deposit in the account, calculate and display the amount of money in the account at the end of each year for 10 years. Use the following formula for determining these amounts:
a = p(1 + r)n
where
p is the original amount invested (i.e., the principal),
r is the annual interest rate,
n is the number of years and
a is the amount on deposit at the end of the n th year.
for year in range(1, 11):
amount = principal * (1 + rate) ** year
print(f'{year:>2}{amount:>10.2f}')
print(f'{year:>2}{amount:>10.2f}')
{year:>2}
>2 to indicate that year’s value should be right aligned (>) in a field of width 2
{amount:>10.2f}
amount as a floating-point number (f) right aligned (>) in a field width of 10 with a decimal point and two digits to the right of the decimal point (.2). 
©1992–2020 by Pearson Education, Inc. All Rights Reserved. This content is based on Chapter 3 of the book Intro to Python for Computer Science and Data Science: Learning to Program with AI, Big Data and the Cloud.
DISCLAIMER: The authors and publisher of this book have used their best efforts in preparing the book. These efforts include the development, research, and testing of the theories and programs to determine their effectiveness. The authors and publisher make no warranty of any kind, expressed or implied, with regard to these programs or to the documentation contained in these books. The authors and publisher shall not be liable in any event for incidental or consequential damages in connection with, or arising out of, the furnishing, performance, or use of these programs.