0

I was going through the basic mathematical operation in python terminal and using format to manage the output.

I tried to generate output with the 10 decimal places.

print('{0:.10f}'.format(1.0/3))

Got this output 0.3333333333

Again I tried to generate output with the 20 decimal places

print('{0:.20f}'.format(1.0/3))

Got this output as 0.33333333333333331483

I think this should return 0.3333333333333333333

Why format function is not working as desired.

Raghvendra
  • 216
  • 3
  • 17

1 Answers1

3

The format function is working normally. This is mainly because of the limitations of programming languages regarding floating point precision when producing decimals from division.

I encourage that you read about that here. https://docs.python.org/3/tutorial/floatingpoint.html

Franrey Saycon
  • 647
  • 1
  • 5
  • 18