Set global output precision python

前端 未结 4 1988
清酒与你
清酒与你 2021-01-04 19:56

I\'ve written a library of functions to make my engineering homework easier, and use them in the python interpreter (kinda like a calculator). Some return matrices, some ret

4条回答
  •  悲&欢浪女
    2021-01-04 20:41

    What you are seeing is the fact that decimal floating point numbers can only be approximated by binary floating point. See Floating Point Arithmetic: Issues and Limitations.

    You could put a module-level variable in your library and use that as the second parameter of round() to round off the return value of the functions in your module, but that is rather drastic.

    If you use ipython (which I would recommend for interactive use, much better than the regular interpreter), you can use the 'magic' function %precision.

提交回复
热议问题