Set floating point precision for pretty printing. Can set either integer precision or a format string. If numpy has been imported and precision is an int, numpy display precision will also be set, via ``numpy.set_printoptions``. If no argument is given, defaults wi
(self, s='')
| 514 | @skip_doctest |
| 515 | @line_magic |
| 516 | def precision(self, s=''): |
| 517 | """Set floating point precision for pretty printing. |
| 518 | |
| 519 | Can set either integer precision or a format string. |
| 520 | |
| 521 | If numpy has been imported and precision is an int, |
| 522 | numpy display precision will also be set, via ``numpy.set_printoptions``. |
| 523 | |
| 524 | If no argument is given, defaults will be restored. |
| 525 | |
| 526 | Examples |
| 527 | -------- |
| 528 | :: |
| 529 | |
| 530 | In [1]: from math import pi |
| 531 | |
| 532 | In [2]: %precision 3 |
| 533 | Out[2]: u'%.3f' |
| 534 | |
| 535 | In [3]: pi |
| 536 | Out[3]: 3.142 |
| 537 | |
| 538 | In [4]: %precision %i |
| 539 | Out[4]: u'%i' |
| 540 | |
| 541 | In [5]: pi |
| 542 | Out[5]: 3 |
| 543 | |
| 544 | In [6]: %precision %e |
| 545 | Out[6]: u'%e' |
| 546 | |
| 547 | In [7]: pi**10 |
| 548 | Out[7]: 9.364805e+04 |
| 549 | |
| 550 | In [8]: %precision |
| 551 | Out[8]: u'%r' |
| 552 | |
| 553 | In [9]: pi**10 |
| 554 | Out[9]: 93648.047476082982 |
| 555 | """ |
| 556 | ptformatter = self.shell.display_formatter.formatters['text/plain'] |
| 557 | ptformatter.float_precision = s |
| 558 | return ptformatter.float_format |
| 559 | |
| 560 | @magic_arguments.magic_arguments() |
| 561 | @magic_arguments.argument( |
nothing calls this directly
no outgoing calls
no test coverage detected