Ask Your Question

Revision history [back]

One way is to use Python string formatting:

sage: print '%.72f'%a
0.000000000000000000000847032947254300339068322500679641962051391601562500

where here we ask for 72 digits after the decimal point.

One way is to use Python string formatting:

sage: a = 1/2^70
sage: print '%.72f'%a
0.000000000000000000000847032947254300339068322500679641962051391601562500

where here we ask for 72 digits after the decimal point.

One way possibility to get what you want is to use Python string formatting:formatting.

This can be done the old way with % and the new way with {}and .format. The old way will accept many types of numbers, the new way requires the entry to have the type of a Python float.

Here is an illustration of both, with 72 digits after the decimal point.

sage: a = 1/2^70
sage: print '%.72f'%a
'%.72f' % a
'0.000000000000000000000847032947254300339068322500679641962051391601562500'
sage: '{:.72f}'.format(float(a))
'0.000000000000000000000847032947254300339068322500679641962051391601562500'

Combine with print to get those displayed without the surrounding ' quotes.

sage: a = 1/2^70
sage: aa = '%.72f' % a
sage: print(aa)
0.000000000000000000000847032947254300339068322500679641962051391601562500
sage: ab = '{:.72f}'.format(float(a))
sage: print(ab)
0.000000000000000000000847032947254300339068322500679641962051391601562500

where here we ask for 72 digits after the decimal point.Related reading:

  • http://ask.sagemath.org/question/11051/cutting-unnecessary-zeroes-in-float-numbers/
  • Python 2 documentation: https://docs.python.org/2/library/string.html
  • Python 3 documentation: https://docs.python.org/3/library/string.html