Change significant figures reporting for default floats

Viewed 59

Is there anyway to set the "default" number of significant figures for python floats or numpy floats?

I hate wrapping the 100+ print statements I have with custom rounding code, that sucks.

1 Answers

There are few ways to approach the problem.

  1. You can write a definition where you will pass your output statements and round the numbers to floating points you need in your definition.
  2. As mentioned in the comment above by GZ0 and answered here Set global output precision python
    you can change your print function

def print(args): builtins.print(("%.2f" % a if isinstance(a, float) else a for a in args))

Related